#include #define ll long long #define mod 1000000007 using namespace std; int power(ll x, ll y) { if(x==0) return 1LL; ll res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x)%mod; // n must be even now y = y>>1; // y = y/2 x = (x*x)%mod; // Change x to x^2 } return res; } int main() { string S,s; S="abcdefghijklmnopqrstuvwxyz"; cin>>s; ll i,j,n,ans,q,pre[100005][30],fact[100005],l,r,su,f[50],ma,ok,x,anss,cnt; n=s.length(); for(i=0;i0) { for(j=0;j<26;j++) pre[i][S[j]-'a']=pre[i-1][S[j]-'a']; pre[i][s[i]-'a']++; } else { for(j=0;j<26;j++) pre[i][S[j]-'a']=0; pre[i][s[i]-'a']++; } } fact[0]=1; for(i=1;i<=100000;i++) fact[i]=(i*fact[i-1])%mod; cin>>q; while(q--) { cin>>l>>r; l--; r--; su=0; if(l==0) { for(i=0;i<26;i++) f[i]=pre[r][S[i]-'a']; } else { for(i=0;i<26;i++) f[i]=pre[r][S[i]-'a']-pre[l-1][S[i]-'a']; } ok=1; for (i=0;i<26;i++) { if(f[i]&1) ok=0; su+=f[i]; } ans=1; if(ok) { ans=(ans*fact[su/2])%mod; for(i=0;i<26;i++) ans=(ans*power(fact[f[i]/2],mod-2))%mod; } else { su=0; x=1; ma=1; cnt=0; for(i=0;i<26;i++) { su+=(f[i]/2); if(f[i]&1) cnt++; } ans=(ans*fact[su])%mod; for(i=0;i<26;i++) ans=(ans*power(fact[f[i]/2],mod-2))%mod; ans=(ans*cnt)%mod; } cout<