#include using namespace std; #define ll long long #define pb push_back #define mp make_pair #define ft first #define sd second #define slld(x) scanf("%lld", &x) #define plld(x) printf("%lld", x) #define nl putchar('\n') const ll MAXN = (ll)1e5 + 8; const ll MOD = (ll)1e9 + 7; ll fact[MAXN]; ll inv[MAXN]; ll pw(ll x, ll y, ll m) { ll res = 1; while(y > 0) { if(y&1) res = (res * x) % m; x = (x*x) % m; y >>= 1; } return res; } void pre() { fact[0] = fact[1] = 1; for(ll i=2; i> T; while(T--) { ll l, r; slld(l); slld(r); for(i = 0; i < 26; i++) freq[i] = g[r][i] - g[l-1][i]; ll uniq_cnt = 0; for(i = 0; i < 26; i++) if(freq[i]==1) uniq_cnt++; ll ans = 1; ll sum = 0; for(i=0; i<26; i++) if(freq[i]>1) { if(freq[i]&1) { freq[i]--; ans = (ans*(inv[freq[i]/2])) % MOD; sum += freq[i]/2, uniq_cnt++; } else ans = (ans*(inv[freq[i]/2])) % MOD, sum += freq[i]/2; } ans = (ans * fact[sum]) % MOD; if(uniq_cnt > 0) { plld((ans * uniq_cnt) % MOD); } else { plld(ans); } nl; } return 0; }