#include #include #include #include #include #define ll long long int #define mod 1000000007 using namespace std; ll power(ll x, ll y, ll m) { if (y == 0) return 1; ll p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } int main() { int n; string s; cin>>s; n = s.size(); vector > arr(n+1); vector a(26,0); vector fact(100010,0),inv(100010,0); fact[0]=inv[0]=1; for(int i=1;i<100010;i++){ fact[i]=i*fact[i-1]; fact[i]%=mod; inv[i]=power(i,mod-2,mod)*inv[i-1]; inv[i]%=mod; } arr[0]=a; for(int i=1;i<=n;i++){ arr[i]=arr[i-1]; arr[i][s[i-1]-'a']++; } int q; cin>>q; while(q--){ int i,u,v; cin>>u>>v; vector a(26,0); ll ans = 1,ct=0,flag=0; for(i=0;i<26;i++){ a[i]=arr[v][i]-arr[u-1][i]; ct+=a[i]/2; ans*=inv[a[i]/2]; ans%=mod; if(a[i]%2) flag++; } ans*= fact[ct]; ans%=mod; if(ct==0 && flag==0){ cout<<"0\n"; } else if(ct==0) cout<