#include <iostream> #include <bits/stdc++.h> using namespace std; #define debug(x) cout<<#x<<" :: "<<x<<"\n"; #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; #define boost ios::sync_with_stdio(0); cin.tie(0) typedef long long ll; typedef double ld; typedef pair<int, int> pii; const int N = 1e5 + 5; const int MOD = 1e9 + 7; /***************************************************************************/ ll power(ll a, ll n, ll m) { if(n == 0) return 1; ll p = power(a, n/2, m); p = (p * p) % m; if(n%2) p = (p * a) % m; return p; } ll fact[N], ifact[N]; void calculateFact() { fact[0] = 1; for(int i=1; i<N; i++) { fact[i] = (i * fact[i-1]) % MOD; } ifact[N-1] = power(fact[N-1], MOD-2, MOD); for(int i=N-1; i>=1; i--) { ifact[i-1] = (i * ifact[i]) % MOD; } } ll nck(int n, int k) { if(n < k) return 0; ll ans = fact[n]; ans = (ans * ifact[k]) % MOD; ans = (ans * ifact[n-k]) % MOD; return ans; } int mpc[26], bpc[26]; int freq[N][26]; int main() { boost; calculateFact(); string str; cin>>str; int len = str.length(); str = '_' + str; for(int i=1; i<=len; i++) { for(int j=0; j<26; j++) { freq[i][j] = freq[i-1][j]; } freq[i][str[i]-'a']++; } int q; cin>>q; while(q--) { int l, r; cin>>l>>r; ll ans = 1; int mp = 0, bp = 0; for(int j=0; j<26; j++) { bpc[j] = (freq[r][j] - freq[l-1][j]) % 2; bp += bpc[j]; mpc[j] = (freq[r][j] - freq[l-1][j] - bpc[j]) / 2; mp += mpc[j]; ans *= ifact[mpc[j]]; ans %= MOD; } ans *= fact[mp]; ans %= MOD; if(bp) ans *= bp; ans %= MOD; cout<<ans<<"\n"; } return 0; }