#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define int long long #define double long double #define trace1(x) cerr<<#x<<": "<<x<<endl #define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl #define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; } const int N=1e5+5; const int MOD=1e9+7; int odd=0, even=0; int fact[N], f[N][26], factinv[N]; vector<int> cur; int modinv(int k) { return pow(k, MOD-2, MOD); } void precomp() { fact[0]=fact[1]=1; factinv[0]=factinv[1]=1; for(int i=1;i<=1e5;i++) { fact[i]=fact[i-1]*i; fact[i]%=MOD; factinv[i]=modinv(fact[i]); } } int calc() { int ans=1; int sum=0; for(auto it:cur) { sum+=it; ans*=factinv[it]; ans%=MOD; } ans*=fact[sum]; ans%=MOD; return ans; } int32_t main() { IOS; precomp(); string s; cin>>s; int n=s.size(); for(int i=0;i<n;i++) { f[i+1][s[i]-'a']++; for(int j=0;j<=25;j++) { f[i+1][j]+=f[i][j]; } } int q; cin>>q; while(q--) { int l, r; cin>>l>>r; l--; odd=0; cur.clear(); for(int j=0;j<=25;j++) { int curr=f[r][j]-f[l][j]; if(!curr) continue; cur.push_back((curr)/2); if(curr%2) odd++; } int ans=calc(); if(odd>0) { ans*=odd; ans%=MOD; } cout<<ans<<endl; } return 0; }