#include using namespace std; typedef long long llong; llong MOD=1e9+7; int sz; vector> info; vector factMod___(100000,1); vector factModInv(100000); llong powMod(llong n, int p) { if(!p) return 1; if(p==1) return n; if(p==2) return (n*n)%MOD; return powMod(powMod(n, p/2),2)*(p%2 ? n:1)%MOD; } void initialize(string s) { // This function is called once before all queries. sz=s.size(); vector cnts(26); for(int i=0; i0; --i) factModInv[i-1] = factModInv[i]*i%MOD; } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. --r,--l; vector cnts = info[r]; if(l) for(int i=0; i<26; ++i) cnts[i] -= info[l-1][i]; llong odds=0, evens=0; vector evenV; for(int i: cnts) { if(i>1) evens+=i/2, evenV.push_back(i/2); if(i%2) ++odds; } llong ans=1; ans *= factMod___[evens]; for(int i: evenV) ans = (ans*factModInv[i])%MOD; if(odds) ans = (ans*odds)%MOD; return ans; } int main() { string s; cin >> s; initialize(s); int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; int result = answerQuery(l, r); cout << result << endl; } return 0; }