#include using namespace std; #define pb push_back #define mp make_pair #define F first #define S second #define fo(i, n) for(int i = 1; i <= n; ++i) typedef long long ll; typedef pair pii; typedef pair pll; const int N = 200200; const int mod = 1e9 + 7; ll f[N], rf[N]; int cnt[N][26]; int q; inline ll bin(ll x, ll k) { ll res = 1; while(k) { if(k & 1) res = res * x % mod; x = x * x % mod; k >>= 1; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = s.length(); s = '#' + s; for(int i = 1; i <= n; ++i) for(int j = 0; j < 26; ++j) cnt[i][j] = cnt[i - 1][j] + (s[i] - 'a' == j); f[0] = rf[0] = 1; fo(i, n) f[i] = f[i - 1] * i % mod; rf[n] = bin(f[n], mod - 2); for(int i = n - 1; i >= 1; --i) rf[i] = rf[i + 1] * (i + 1) % mod; cin >> q; while(q--) { int l, r; cin >> l >> r; int half = 0, center = 0; for(int i = 0; i < 26; ++i) { int cur = cnt[r][i] - cnt[l - 1][i]; half += cur / 2; center += cur % 2; } ll res = f[half]; for(int i = 0; i < 26; ++i) { int cur = cnt[r][i] - cnt[l - 1][i]; cur /= 2; res = res * rf[cur] % mod; } if(center) res = res * center % mod; cout << res << '\n'; } return 0; }