#include using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 7; ll arr[MAXN][26]; ll fact[MAXN]; ll invn[MAXN]; ll invfact[MAXN]; void preprocess(){ invn[1] = 1; for(int i = 2; i < MAXN; i++)invn[i] = (MOD - (MOD/i) * invn[MOD%i] % MOD) % MOD; fact[0] = 1; for(int i = 1; i < MAXN; i++)fact[i] = (i*fact[i-1])%MOD; invfact[0] = 1; for(int i = 1; i < MAXN; i++)invfact[i] = (invn[i]*invfact[i-1])%MOD; return; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string in; cin >> in; int n = in.length(); preprocess(); for(int i = 1; i <= n; i++){ for(int j = 0; j < 26; j++){ if(in.at(i-1) == (char) ('a' + j)){ arr[i][j] = arr[i-1][j] + 1; }else{ arr[i][j] = arr[i-1][j]; } } } int q; cin >> q; while(q--){ ll l,r; cin >> l >> r; ll temp_arr[26]; for(int i = 0; i < 26; i++){ temp_arr[i] = arr[r][i] - arr[l-1][i]; } ll sum = 0; ll odd = 0; for(int i = 0; i < 26; i++){ sum += temp_arr[i]/2; odd += temp_arr[i]%2; //cout << temp_arr[i] << " "; } //cout << endl; //cout << sum << endl; if(odd == 0)odd = 1; ll ans = fact[sum]; //cout << ans << endl; for(int i = 0; i < 26; i++){ ans = (ans*invfact[temp_arr[i]/2])%MOD; //cout << ans << endl; } ans = (ans*odd)%MOD; cout << ans << endl; } return 0; }