#include using namespace std; typedef long long Int; const Int MOD = 1e9 + 7; const int MAXL = 1e5; Int Count[MAXL + 10][26]; Int permute[MAXL+10]; Int ipermute[MAXL+10]; Int power(Int a,Int b) { Int ans = 1; while(b) { if(b&1) { ans = (ans*a)%MOD; } a = (a*a)%MOD; b /= 2; } return ans; } void initialize(string s) { for(int i = 1;i <= s.length();++i) { for(int j = 0;j < 26;++j) Count[i][j] += Count[i-1][j]; Count[i][s[i-1] - 'a'] += 1; } permute[0] = permute[1] = 1; ipermute[0] = ipermute[1] = 1; for(Int i = 2;i <= MAXL;++i) { permute[i] = (permute[i-1]*i)%MOD; ipermute[i] = (power(i,MOD-2)*ipermute[i-1])%MOD; } } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. Int q[26]; Int right = 0,odds = 0; vector divisors; for(int i = 0;i < 26;++i) { q[i] = Count[r][i] - Count[l-1][i]; right += q[i]/2; if(q[i] > 3) { divisors.push_back(q[i]/2); } if(q[i]%2 == 1) odds += 1; } Int ans = permute[right]; for(auto i : divisors) { ans = (ans*ipermute[i])%MOD; } if(odds) { ans = (ans*odds)%MOD; } return ans; } int main() { #ifdef DEBUG freopen("in.txt","r",stdin); #endif 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; }