#include using namespace std; #define ms(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORd(i, a, b) for (ll i = (a) - 1; i >= (b); i--) #define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define sz(a) int((a).size()) #define present(t, x) (t.find(x) != t.end()) #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed<> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair pi; typedef vector vi; typedef vector vii; #define db(x) cerr << #x << " = " << (x) << " "< 0) { if (exponent % 2 == 1) result = (result * base) % modulus; exponent = exponent >> 1; base = (base * base) % modulus; } return result; } void pre(ll n) { fact[0] = 1 ; FOR(i,1,n) { fact[i] = (i*fact[i-1])%mod ; } FOR(i,0,n) { ifact[i] = modular_pow(fact[i],mod-2,mod) ; } } void output() { string s ; cin>>s ; ll n = s.size() ; pre(n+10) ; ll f[n][26] ; FOR(i,0,n) { FOR(j,0,26) { f[i][j] = 0 ; } } f[0][s[0]-'a']++ ; FOR(i,1,n) { FOR(j,0,26) { f[i][j] = f[i-1][j] ; } f[i][s[i]-'a']++ ; } // FOR(i,0,26) // { // db(f[n-1][i]) ; // } ll q ; cin>>q ; FOR(k,0,q) { ll l,r ; cin>>l>>r ; l-- ; r-- ; ll cum[26] ; if(l==0) { FOR(i,0,26) { cum[i] = f[r][i] ; } } else { FOR(i,0,26) { cum[i] = f[r][i]-f[l-1][i] ; } } // FOR(i,0,26) // { // db(cum[i]) ; // } vector elen ; ll sum = 0 ; ll oddc = 0 ; FOR(i,0,26) { if((cum[i]/2)>0) { elen.pb(cum[i]/2) ; } sum+= (cum[i]/2) ; if(cum[i]%2==1) { oddc++ ; } } // db(elen.size()) ; ll ans = fact[sum] ; // db(ans) ; for(ll x : elen) { // db(x) ; // db(ans) ; ans = (ans*ifact[x])%mod ; } if(oddc>0) { ans = (ans*(oddc))%mod ; } cout<