#include #define loop(i,a,b) for(int i=a;i=b;i--) #define loopm(i,a,b,step) for(int i=a;i=b;i-=step) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define init(arr,val) memset(arr,val,sizeof(arr)) #define INF 1000000007 #define MOD 1000000007 #define BINF 1000000000000000001 #define int long long int #define double long double using namespace std; int fxp(int a,int b,int mod) { if(b==0) return 1; else if(b==1) return a; else { if(b%2==0) { return ((fxp(a,b/2,mod)%mod)*(fxp(a,b/2,mod)%mod))%mod; } else { return (a*(fxp(a,b/2,mod)%mod)*(fxp(a,b/2,mod)%mod))%mod; } } } void EE(int a,int b,int &x,int &y) { if(a%b==0) { x=0; y=1; return; } EE(b,a%b,x,y); int temp=x; x=y; y=temp-y*(a/b); } int inverse(int a,int m) { int x,y; EE(a,m,x,y); if(x<0) x+=m; return x; } #undef int int main() { #define int long long int ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin>>s; int n=s.size(); int precomputation[n][26]; memset(precomputation,0,sizeof(precomputation)); precomputation[0][(int)(s[0]-'a')]=1; loop(i,1,n) { char a=s[i]; loop(j,0,26) precomputation[i][j]=precomputation[i-1][j]; precomputation[i][(int)(a-'a')]+=1; } int fact[n+1]; int modinvfact[n+1]; fact[0]=1; loop(i,1,n+1) fact[i]=(i*fact[i-1])%MOD; loop(i,0,n+1) { modinvfact[i]=inverse(fact[i],MOD); } int q; cin>>q; while(q--) { int even=0,odd=0; int cntev=0; int arr[26]; int l,r; cin>>l>>r; l-=1; r-=1; l-=1; if(l<0) { loop(i,0,26) arr[i]=precomputation[r][i]; } else { loop(i,0,26) { arr[i]=precomputation[r][i]-precomputation[l][i]; } } vectorsecarr; loop(i,0,26) { even+=(arr[i])/2; secarr.pb((arr[i]/2)); if(arr[i]%2!=0) odd++; if(arr[i]!=1) cntev++; } int maxlength=2*even; if(odd>0) maxlength++; int ans=fact[even]; loop(i,0,secarr.size()) { ans=(ans*modinvfact[secarr[i]])%MOD; } if(odd>0) ans=(ans*odd)%MOD; cout<