#include using namespace std; #define ll long long ll fact[200100],arr[100100][54]; ll M=1e9+7; void pre () { ll i; fact[0]=1; for (i=1;i<=200000;i++) fact[i]=i*fact[i-1],fact[i]%=M; } ll fexpo (ll a,ll b) { ll res=1; while (b) { if (b&1) { res*=a; res%=M; } a*=a; a%=M; b/=2; } return res; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ ll t,n,m,i,j,k,l,q; ios_base::sync_with_stdio(0); cin.tie(0); pre(); string str; cin>>str; n=str.length(); for (i=1;i<=n;i++) { for (j=0;j<52;j++) arr[i][j]=arr[i-1][j]; ll op; if (str[i-1]<='Z') op=str[i-1]-'A'; else op=str[i-1]-'a'+26; arr[i][op]++; } cin>>q; while (q--) { cin>>j>>k; ll ans=1,sum=0; ll flag=0; for (i=0;i<52;i++) { ll op = arr[k][i]-arr[j-1][i]; sum+=(op/2); if (op%2) flag++; ans=ans*fact[op/2]; ans%=M; } // cout<