#include #define MOD 1000000007 #define pb push_back #define xx first #define yy second #define all(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i 0) { if (exp & 1) result = (result *base) % MOD; base = (base * 1ll * base) % MOD; exp >>= 1; } return result; } ll inv(ll a){ return modpow(a,MOD - 2); } ll calc(){ ll res = 1; int pr = 0,imp = 0,sum = 0; rep(i,26){ if(ch[i] > 1){ res = (res * inv(ft[ch[i] >> 1])) % MOD, sum += (ch[i] >> 1); } if(ch[i] & 1)imp++; } res = (res * ft[sum]) % MOD; if(imp > 0)res = (res * imp) % MOD; return res; } void add(int a){ ch[s[a]-'a']++; } void remove(int a){ ch[s[a]-'a']--; } int main(){ int n,q,a,b; scanf("%s",s); scanf("%d",&q); n = strlen(s); sq = sqrt(n); fact(); //querries && ans ll ans[q]; for(int i = 0;iqq[i].l)add(--curl); while(currqq[i].r)remove(curr--); ans[qq[i].ind] = calc(); } for(int i = 0;i