#include // PLEASE using namespace std; typedef long long ll; typedef pair pp; #define MAXN 300005 #define MAXM 1005 #define MAXP 25 #define A first #define B second #define MP make_pair #define PB push_back const ll INF = 2e9+13; const ll MOD = 1e9+7; int N, Q; string s; int pre[26][MAXN]; ll fac[MAXN]; ll ifa[MAXN]; inline int get(int c, int l, int r) { if(l == 0) return pre[c][r]; return pre[c][r] - pre[c][l-1]; } ll mmul(ll a, ll b) { return (a*b)%MOD; } ll madd(ll a, ll b) { return (a+b)%MOD; } ll pmod(ll a, ll b) { ll ret = 1; while(b) { if(b%2) ret = mmul(ret, a); a = mmul(a, a); b /= 2LL; } return ret; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cin >> s; N = (int)s.length(); pre[s[0]-'a'][0] = 1; for(int i=1; i> Q; while(Q--) { int l, r; cin >> l >> r; --l, --r; // first calculate length vector cnts; for(int i=0; i<26; i++) cnts.PB(get(i, l, r)); sort(cnts.begin(), cnts.end()); bool f = 0; int len = 0; for(int i=0; i<26; i++) { if((!f) && (cnts[i]%2)) { len += cnts[i]; f = 1; } else len += (cnts[i]/2)*2; } if((len%2) == 0) { ll ret = fac[len/2]; for(int i=0; i<26; i++) { int x = cnts[i]/2; ret = mmul(ret, ifa[x]); } cout << ret << endl; } else { // pick a middle ll ret = fac[len/2]; for(int i=0; i<26; i++) { int x = cnts[i]/2; ret = mmul(ret, ifa[x]); } ll cntmid = 0; for(int i=0; i<26; i++) if(cnts[i]%2) cntmid++; ret = mmul(ret, cntmid); cout << ret << endl; } } }