#include #include #include #include #include #include #include #include #include using namespace std; #define sz(x) (int)(x.size()) #define fi(a,b) for(int i=a;i=b;--i) #define fdj(a,b) for(int j=a-1;j>=b;--j) #define fdo(a,b) for(int o=a-1;o>=b;--o) #define pb push_back #define mp make_pair typedef long long ll; typedef pair pii; typedef vector vi; typedef unsigned long long ull; ////////////////////// int const N = 1e5 + 41; ull const ONE = 1; int const MOD = 1e9 + 7; int qu; int n, l[N], r[N]; char s[N]; vi vq[N]; int f[N], invf[N]; int ans[N], ansl[N]; int mul(int a, int b){ return (ll) a * b % MOD; } void add(int &a, int b){ a += b; if(a >= MOD) a -= MOD; } int bp(int x, int d){ int res = 1; while(d){ if(d&1) res = mul(res, x); x = mul(x, x); d >>= 1; } return res; } void init(){ f[0] = 1; fi(1, N) f[i] = mul(f[i-1], i); fi(0, N) invf[i] = bp(f[i], MOD-2); } vi getdiff(vi a, vi b){ vi res = vi(26, 0); fi(0, sz(a)) res[i] = a[i] - b[i]; return res; } int getways(vi &a){ int res; int n = 0; fi(0, sz(a)) n += a[i] / 2; res = f[n]; fi(0, sz(a)) res = mul(res, invf[a[i] / 2]); return res; } void solve(){ n = strlen(s); vq[0] = vi(26, 0); fi(1, n+1){ vq[i] = vq[i-1]; vq[i][s[i-1]-'a'] += 1; } fi(0, qu){ vi v = getdiff(vq[r[i]], vq[l[i]-1]); bool f = false; fo(0, sz(v)) if(v[o] & 1) f = true; if(!f){ ans[i] = getways(v); }else{ fj(0, 26){ if(v[j] & 1){ add(ans[i], getways(v)); } } } } } int main(){ #ifdef _DEBUG freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif init(); cin >> s; cin >> qu; fi(0, qu){ cin >> l[i] >> r[i]; } solve(); fi(0, qu){ cout << ans[i] << endl; } return 0; }