#include #include #include #include #include using namespace std; typedef long long ll; const int MAXN = 1e5+6.66; const ll MOD = 1e9+7; int par[MAXN][26]; long long fact[MAXN]; void init_fact() { fact[0] = 1; for(int i =1;i>1)*(exp&1?base:1)%MOD; } int main() { string str;cin >> str; init_fact(); for(int i = 1;i<=str.length();i++) { par[i][str[i-1]-'a']++; for(int j = 0;j<26;j++) par[i][j] += par[i-1][j]; } int q;cin >> q; while(q--) { int l,r;cin >> l >> r; int MOD2 = 0; int cnt = 0; for(int i = 0;i<26;i++) cnt += (par[r][i]-par[l-1][i])/2,MOD2 += (par[r][i]-par[l-1][i])&1; ll ans = fact[cnt]; for(int i = 0;i<26;i++) (ans *= POW(fact[(par[r][i]-par[l-1][i])/2],MOD-2))%=MOD; if(MOD2)(ans *= MOD2)%=MOD; cout << ans << endl; } return 0; }