#include #define REP(i, n) for (int i = 0; (i) < int(n); ++ (i)) using ll = long long; using namespace std; ll powmod(ll x, ll y, ll p) { assert (0 <= x and x < p); assert (0 <= y); ll z = 1; for (ll i = 1; i <= y; i <<= 1) { if (y & i) z = z * x % p; x = x * x % p; } return z; } ll modinv(ll x, ll p) { assert (x % p != 0); return powmod(x, p - 2, p); } template int fact(int n) { static vector memo(1, 1); while (n >= memo.size()) { memo.push_back(memo.back() *(ll) memo.size() % MOD); } return memo[n]; } template int inv_fact(int n) { static vector memo(1, 1); while (n >= memo.size()) { memo.push_back(memo.back() *(ll) modinv(memo.size(), PRIME) % PRIME); } return memo[n]; } template int choose(int n, int r) { if (n < r) return 0; return fact(n) *(ll) inv_fact(n - r) % MOD *(ll) inv_fact(r) % MOD; } constexpr int mod = 1e9 + 7; int main() { // input string s; cin >> s; // prepare int n = s.length(); vector > acc(n + 1); acc[0] = {}; REP (i, n) { acc[i + 1] = acc[i]; acc[i + 1][s[i] - 'a'] += 1; } // serve int q; cin >> q; while (q --) { int l, r; cin >> l >> r; -- l; ll result = 1; int even = 0; int odd = 0; REP (c, 26) { int cnt = acc[r][c] - acc[l][c]; result = result * choose(even + cnt / 2, cnt / 2) % mod; even += cnt / 2; odd += cnt % 2; } result = result * max(1, odd) % mod; cout << result << endl; } return 0; }