#include #define MOD 1000000007 using namespace std; int cnt[100005][26]; long long fac[100005]; long long raise(long long b, long long e) { long long r = 1; while(e) { if(e & 1) r = r * b % MOD; b = b * b % MOD; e >>= 1; } return r; } void initialize(string s) { // This function is called once before all queries. fac[0] = 1; for(int i = 1; i <= 100000; i++) fac[i] = fac[i - 1] * i % MOD; for(int i = 0; i < (int)s.length(); i++) { if(i > 0) for(int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j]; cnt[i][s[i] - 'a']++; } } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. int oddcnt = 0; int f[26] = {0}; int palLen = 0; for(int i = 0; i < 26; i++) { if(l > 0) { if((cnt[r][i] - cnt[l - 1][i]) & 1) oddcnt++; f[i] = cnt[r][i] - cnt[l - 1][i]; //cout<<'a' + i<<" "<> 1); } else { if(cnt[r][i] & 1) oddcnt++; f[i] = cnt[r][i]; //cout<<'a' + i<<" "<> 1); } } long long ans = 0; ans = fac[palLen]; //cout<<"Ans: "<>= 1; if(f[i] > 0) { ans = (ans * raise(fac[f[i]], MOD - 2)) % MOD; } } if(oddcnt > 0) ans = (ans * oddcnt) % 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; r--; l--; int result = answerQuery(l, r); cout << result << endl; } return 0; }