#include #define rand() ((rand()<<15)+rand()) using namespace std; /* #include #include #include using namespace __gnu_pbds; template using hash_map = cc_hash_table; template> using oset = tree; */ typedef long long lint; typedef complex point; const int INF = 0x3f3f3f3f; const lint INFL = 0x3f3f3f3f3f3f3f3fLL; const double E = 1e-9, pi = 2 * acos(0); template void amin(T &x, U y) { if (y < x) x = y; } template void amax(T &x, U y) { if (x < y) x = y; } const int S = 26, N = 100'000, MOD = 1'000'000'007; int counter[S][N + 1], fac[N + 1], inv[N + 1]; bool solve(int testNumber) { string str; if (!(cin >> str)) { return false; } for (int i = 0; i < S; i++) { for (int j = 1; j <= (int)str.size(); j++) { counter[i][j] = counter[i][j - 1]; if (str[j - 1] - 'a' == i) { counter[i][j]++; } } } int q; cin >> q; for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; int sum = 0, odd = 0, ans = 1; for (int j = 0; j < S; j++) { int x = counter[j][r] - counter[j][l - 1]; sum += x / 2; odd += x % 2; ans = (lint)ans * inv[x / 2] % MOD; } ans = (lint)ans * fac[sum] % MOD; if (odd) { ans = (lint)ans * odd % MOD; } printf("%d\n", ans); } return true; } int modpow(int a, lint b) { int ans = 1; while (b) { if (b % 2) { ans = (lint)ans * a % MOD; } a = (lint)a * a % MOD; b /= 2; } return ans; } int inverse(int a) { return modpow(a, MOD - 2); } void init(const char *in = nullptr, const char *out = nullptr) { if (in) freopen(in, "r", stdin); if (out) freopen(out, "w", stdout); srand(unsigned((long long)new char)); fac[0] = 1; for (int i = 1; i <= N; i++) { fac[i] = (lint)fac[i - 1] * i % MOD; } inv[N] = inverse(fac[N]); for (int i = N - 1; i >= 0; i--) { inv[i] = (lint)inv[i + 1] * (i + 1) % MOD; } } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); init(); for (int i=1; solve(i); i++); return 0; }