#include using namespace std; using ll = long long; const ll mod = 1e9 + 7; const int MAX = 1e5; ll fact[MAX + 1], rfac[MAX + 1]; ll Pow(ll val, ll x) { ll res = 1; while (x) { if (x & 1) res = (res * val) % mod; val = (val * val) % mod; x >>= 1; } return res; } void init() { fact[0] = 1; for (int i = 1; i <= MAX; i++) { fact[i] = fact[i - 1] * i % mod; } rfac[MAX] = Pow(fact[MAX], mod - 2); for (int i = MAX - 1; i >= 0; i--) { rfac[i] = rfac[i + 1] * (i + 1) % mod; } } ll nCr(ll n, ll r) { if (r < 0 || n < r) return 0; return fact[n] * rfac[n - r] % mod * rfac[r] % mod; } int main() { init(); ios::sync_with_stdio(false), cin.tie(0); string s; int q; cin >> s >> q; int n = s.size(); vector> cnt(n + 1, vector(26)); for (int i = 0; i < n; i++) { cnt[i + 1] = cnt[i]; cnt[i + 1][s[i] - 'a']++; } while (q--) { int l, r; cin >> l >> r; l--; vector t(26); int odd = 0, sum = 0; vector p; for (int i = 0; i < 26; i++) { t[i] = cnt[r][i] - cnt[l][i]; odd += t[i] & 1; sum += t[i] / 2; p.push_back(t[i] / 2); } ll res = odd ? odd : 1; for (ll val : p) { (res *= nCr(sum, val)) %= mod; sum -= val; } cout << res << endl; } return 0; }