/* In the name of Allah */ #include using namespace std; #define X first #define Y second #define pb push_back #define mp make_pair #define Size(x) ((int)(x).size()) #define Precision(i) cout << fixed << setprecision(i) typedef long long ll; typedef long double ld; typedef pair pii; const int MAX_N = 1e5 + 10, P = 1e9 + 7; int a[MAX_N][26 + 4]; ll f[MAX_N] = {1}; int power(ll n, ll k) { if(k == 0) return 1; ll ans = power(n, k / 2); ans *= ans, ans %= P; if(k % 2) ans *= n, ans %= P; return ans; } int main() { ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0); for(int i = 1; i < MAX_N; i++) f[i] = f[i - 1] * i, f[i] %= P; string s; cin >> s; for(int i = 0; i < Size(s); i++) { for(int j = 0; j < 30; j++) a[i + 1][j] = a[i][j]; a[i + 1][s[i] - 'a']++; } int q; cin >> q; while(q--) { int l, r; cin >> l >> r; int x[26 + 4]; for(int i = 0; i < 30; i++) x[i] = a[r][i] - a[l - 1][i]; ll d = 1, dis = 0; int odd = 0; for(int i = 0; i < 30; i++) { dis += x[i] / 2; d *= f[x[i] / 2]; d %= P; if(x[i] % 2) odd++; } dis = (f[dis] * max(odd, 1)) % P; dis *= power(d, P - 2); dis %= P; cout << dis << endl; } return 0; }