#include "bits/stdc++.h" using namespace std; #define ll long long int #define mod 1000000007 const int N = 1e5 + 5; int n, q; char s[N]; int pre[N][26]; int fac[N], invf[N]; ll po(ll b, ll e) { ll res = 1; while( e ) { if(e % 2) res = (res * b) % mod; b = (b * b) % mod; e /= 2; } return res % mod; } int main() { fac[0] = invf[0] = 1; for(int i = 1 ; i < N ; i++) { fac[i] = (fac[i - 1] * 1LL * i) % mod; invf[i] = (invf[i - 1] * 1LL * po(i, mod - 2)) % mod; } scanf("%s", s + 1); n = strlen(s + 1); for(int i = 1 ; i <= n ; i++) { for(int j = 0 ; j < 26 ; j++) pre[i][j] = pre[i - 1][j]; pre[i][s[i] - 'a']++; } scanf("%d", &q); while( q-- ) { int l, r; scanf("%d %d", &l, &r); int cnt[26] = {0}; for(int i = 0 ; i < 26 ; i++) cnt[i] = pre[r][i] - pre[l - 1][i]; int odd = 0; int tot = 0; for(int i = 0 ; i < 26 ; i++) { if(cnt[i] % 2) odd++; cnt[i] /= 2; tot += cnt[i]; } ll ans = fac[tot]; for(int i = 0 ; i < 26 ; i++) ans = (ans * 1LL * invf[cnt[i]]) % mod; if(odd) ans = (ans * odd) % mod; printf("%lld\n", ans); } return 0; }