#include #define si( x ) scanf("%d", &x) #define sll( x ) scanf("%I64d", &x) #define mp make_pair #define pb push_back #define ff first #define ss second #define rep(i,a,b) for(int i = (a); i <= (b); i++) using namespace std; int mod = 1e9 + 7, ans; int a[100005][30]; int fac[100005]; void initialize(string s) { a[1][s[0]-'a'] = 1; rep(i,2,s.size()){ rep(j,0,28) a[i][j] = a[i-1][j]; a[i][s[i-1] - 'a']++; } fac[1] = 1; rep(i,2,100004){ long long tt = 1ll*fac[i-1]*i; fac[i] = tt % mod; } return; } int pov(int aa,int bb){ long long x=1,y=aa; while(bb > 0){ if(bb%2 == 1){ x=(x*y)%mod; } y = (y*y)%mod; // squaring the base bb /= 2; } return x%mod; } int answerQuery(int l, int r) { int x[30]; rep(i,0,28) x[i] = a[r][i] - a[l-1][i]; int s = 0, y = 0; vector v1, v2; rep(i,0,25){ if(x[i] % 2) y++; s += (x[i]/2) * 2; if(x[i]/2 > 0) v1.pb(x[i]/2); } if(y) s++; // if(s % 2 == 0){ int k = 0; rep(i,0,v1.size()-1) k += v1[i]; int ans = fac[k]; //cout << "fergr" << " " << ans << endl; rep(i,0,v1.size()-1){ int dd = pov(v1[i],mod-2); // cout << i <<" " << dd << endl; long long tt = 1ll * dd * ans; ans = tt % mod; } // return ans; //} if(s%2){ long long tt = 1ll * ans * y; ans = tt % 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; }