#include using namespace std; #define ll long long int #define mp make_pair #define mod 1000000007 #define pb push_back ll power(ll a,ll b) { if(b==0) return 1; ll z=power(a,b/2); if(b%2==0) return (z*z)%mod; return (((z*z)%mod)*a)%mod; } char s[112345]; struct node{ ll l[27]; }; struct node tree[412345]; void build(int low,int high,int pos) { if(low==high) { for(int i=0;i<26;i++) tree[pos].l[i]=0; tree[pos].l[s[low]-'a']++; return; } int mid=(low+high)/2; build(low,mid,2*pos+1); build(mid+1,high,2*pos+2); for(int i=0;i<26;i++) tree[pos].l[i]=tree[2*pos+1].l[i]+tree[2*pos+2].l[i]; return; } void query(int low,int high,int qlow,int qhigh,int pos,ll arr[27]) { if(low>qhigh || high> q; ll fact[112345],inv[112345]; fact[0]=1,inv[0]=1; for(ll i=1;i<112345;i++){ fact[i]=(fact[i-1]*i)%mod; inv[i]=power(fact[i],mod-2); } while(q--) { int l,r; scanf("%d%d",&l,&r); ll arr[27]={0}; l--,r--; query(0,n-1,l,r,0,arr); ll cnt=0,z=0,ans; for(int i=0;i<26;i++) { z+=arr[i]/2; if(arr[i]%2) cnt++; } if(cnt==0) { ans=fact[z]; for(int i=0;i<26;i++) ans=(ans*inv[arr[i]/2])%mod; } else { ans=fact[z]; for(int i=0;i<26;i++) ans=(ans*inv[arr[i]/2])%mod; ans=(ans*cnt)%mod; } printf("%lld\n",ans); } }