#include #define mod 1000000007 using namespace std; long hasht[100005][26]; long factmod[100005]; void initialize(string s) { // This function is called once before all queries. for(long i=0;i<100005;i++) for(int j=0;j<26;j++) hasht[i][j]=0; hasht[0][s[0]-'a']=1; for(long i=1;i 1) { // q is quotient q = num / m; t = m; // m is remainder now, process same as // Euclid's algo m = num % m, num = t; t = x0; x0 = x1 - q * x0; x1 = t; } // Make x1 positive if (x1 < 0) x1 += m0; return x1; } long answerQuery(long l, long r) { // Return the answer for this query modulo 1000000007. l--;r--; long qt[26],sum=0; int nodd=0; for(int i=0;i<26;i++){ qt[i]=hasht[r][i]; if(l-1>=0) qt[i]-=hasht[l-1][i]; if(qt[i]%2) nodd++; sum+=(qt[i]/2); } if(!nodd) nodd=1; long ans=nodd; ans=((long long)ans*factmod[sum])%mod; for(int i=0;i<26;i++){ ans=((long long)ans*revmod(factmod[(qt[i]/2)], mod))%mod; } return ans; } int main() { string s; cin >> s; initialize(s); long q; cin >> q; for(long a0 = 0; a0 < q; a0++){ long l; long r; cin >> l >> r; long result = answerQuery(l, r); cout << result << endl; } //cout << revmod(1,mod) << endl; return 0; }