// We are the ones that rule the world now // You are entrapped by blind inanity // There is no way that you'll revoke your decision // Now look for distraction #include using namespace std; #define ll long long const ll MOD = 1e9 + 7; char str[100005]; ll num[30][100005], fac[100005], now[30]; ll modexp(ll b, ll e) { ll r = 1ll; while (e) { if (e&1) r = (r*b) % MOD; e >>= 1; b = (b*b) % MOD; } return (ll) r; } void init() { fac[0] = 1; for (ll i = 1; i <= 100000; i++) { fac[i] = (fac[i-1]*i)% MOD; } } int main() { init(); scanf("%s", str); int pnj = strlen(str); for (int i = 0; i < pnj; i++) { int x = str[i] - 'a'; if (i > 0) { for (int j = 0; j < 26; j++) num[j][i] = num[j][i-1]; } num[x][i]++; } int t; scanf("%d", &t); while (t--) { int l, r; scanf("%d %d", &l, &r); l--, r--; memset(now, 0, sizeof(now)); ll ans = 1, len = 0, pmb = 1, gnj = 0; for (int i = 0; i < 26; i++) { now[i] = num[i][r]; if (l > 0) now[i] -= num[i][l-1]; if (now[i] & 1) gnj++; len += now[i]/2; pmb = (pmb * modexp(fac[now[i]/2], MOD - 2)) % MOD; } // printf("len = %lld\n", len); ans = (ans * pmb) % MOD; ans = (ans * fac[len]) % MOD; ans = (ans * max(1ll, gnj)) % MOD; printf("%lld\n", ans); } }