#include using namespace std; const int ALPHA = 26; const int MAXN = 100010; const int MOD = 1000000007; int cnt[ALPHA][MAXN]; int fac[MAXN]; char s[MAXN]; int add(int a, int b){ return (a + b) % MOD; } int mul(int a, int b){ return (long long)a * b % MOD; } int pw(int a, int b){ if(b == 0) return 1; if(b & 1) return mul(a, pw(a, b - 1)); int half = pw(a, b / 2); return mul(half, half); } int inv(int x){ return pw(x, MOD - 2); } int solve1(vector &p){ int sm = 0; int ret = 1; for(auto x : p){ ret = mul(ret, inv(fac[x])); sm += x; } ret = mul(ret, fac[sm]); return ret; } int solve(vector &d){ vector pairs; int odd = 0; for(auto x : d){ if(x > 1) pairs.push_back(x / 2); odd += x & 1; } return mul(solve1(pairs), max(1, odd)); } int main(){ fac[0] = 1; for(int i = 1; i < MAXN; i++) fac[i] = mul(fac[i - 1], i); scanf("%s", s + 1); int n = strlen(s + 1); for(int i = 1; i <= n; i++){ for(int l = 0; l < ALPHA; l++) cnt[l][i] = cnt[l][i - 1]; cnt[s[i] - 'a'][i]++; } int q; scanf("%d", &q); while(q--){ int from, to; scanf("%d %d", &from, &to); vector d; for(int l = 0; l < ALPHA; l++) d.push_back(cnt[l][to] - cnt[l][from - 1]); printf("%d\n", solve(d)); } return 0; }