#include #define lsb(x) (x & (-x)) #define ll long long using namespace std; const int MOD = (int) 1e9 + 7; const int MAXN = (int) 1e5; int sp[MAXN + 1][26]; string str; int fact[MAXN + 1]; inline int lgput(int a, int b) { int ans = 1; while(b > 0) { if(b & 1) ans = (1LL * ans * a) % MOD; a = (1LL * a * a) % MOD; b >>= 1; } return ans; } inline int comb(int n, int k) { return (1LL * fact[n] * lgput((1LL * fact[k] * fact[n - k]) % MOD, MOD - 2)) % MOD; } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, q, l, r, j; ios::sync_with_stdio(false); cin >> str; int n = str.size(); fact[0] = 1; for(i = 1; i <= n; i++) { fact[i] = (1LL * fact[i - 1] * i) % MOD; } str = " " + str; for(i = 1; i <= n; i++) { str[i] -= 'a'; for(j = 0; j < 26; j++) { sp[i][j] = sp[i - 1][j]; } sp[i][str[i]]++; } cin >> q; while(q > 0) { q--; cin >> l >> r; int sz = 0; for(i = 0; i < 26; i++) { int nr = sp[r][i] - sp[l - 1][i]; sz += nr - (nr % 2); } int ans = 1; int cnt = 0; for(i = 0; i < 26; i++) { int nr = sp[r][i] - sp[l - 1][i]; if(nr % 2 == 1) { cnt++; nr--; } if(nr > 0) ans = (1LL * ans * comb(sz / 2, nr / 2)) % MOD; sz -= nr; } if(cnt > 0) ans = (1LL * ans * cnt) % MOD; cout << ans << "\n"; } //cin.close(); //cout.close(); return 0; }