//Author : Ayush Jain #include using namespace std; #define ull unsigned long long #define ll long long #define mod 1000000007 #define fi first #define se second #define PI acos(-1.0) const int N=1e5 + 5; const int M=1e5 + 5; ull pw[67]; void pre() { pw[0]=1; for(int i=1;i<64;i++) pw[i]=2*pw[i-1]; } char s[N]; struct node { int arr[26]; node(){ for(int i=0;i<26;i++){ arr[i]=0; } } }; struct node tree[400005]; void build(int node,int start,int end) { if(start==end){ tree[node].arr[s[start]-'a']++; return ; } int mid=(start + end)/2; build(2*node+1,start,mid); build(2*node+2,1+mid,end); for(int i=0;i<26;i++){ tree[node].arr[i]+=tree[2*node+1].arr[i]; tree[node].arr[i]+=tree[2*node+2].arr[i]; } } struct node quer(int node,int start,int end,int l,int r) { struct node foo; if(start>=l && end<=r){ //cout<<"h\n"; for(int i=0;i<26;i++){ foo.arr[i]+=tree[node].arr[i]; } // for(int i=0;i<26;i++){ // cout<r || end0){ if(power%2==0){ cur=(cur*cur)%mod; } else{ res=(res*cur)%mod; cur=(cur*cur)%mod; } power/=2; } return res; } int main() { ios_base::sync_with_stdio(false); pre(); ll f[N]; f[1]=1; f[0]=1; for(ll i=2;i>s; int n=strlen(s); build(0,0,n-1); int qq; cin>>qq; while(qq--){ int l,r; cin>>l>>r; struct node foo=quer(0,0,n-1,l-1,r-1); vector v; ll odd=0,sum=0; for(int i=0;i<26;i++){ if(foo.arr[i]>0){ if(foo.arr[i]%2==0){ v.push_back((ll)foo.arr[i]/2); } else{ v.push_back((ll)foo.arr[i]/2); odd++; } sum+=(ll)foo.arr[i]/2; } } ll fa=f[sum]; for(int i=0;i0) fa=(fa*odd)%mod; cout<