#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args<< " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// -----------------------------------------------------------------------------
const LL maxn = 1E5 + 5;
const LL MOD = 1E9 + 7;
char s[maxn];
LL a[maxn][26];
LL c[maxn], Q, l, r;

LL pown(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
LL invf[maxn], fac[maxn];
void fac_inv_init(LL n, LL p) {
    fac[0] = 1;
    FOR (i, 1, n)
        fac[i] = i * fac[i - 1] % p;
    invf[n - 1] = pown(fac[n - 1], p - 2, p);
    FORD (i, n - 2, -1)
        invf[i] = invf[i + 1] * (i + 1) % p;
}

int main() {
    fac_inv_init(maxn, MOD);
    scanf("%s", s);
    FOR (i, 0, strlen(s)) {
        FOR (j, 0, 26)
            a[i + 1][j] = a[i][j];
        a[i + 1][s[i] - 'a']++;
    }
    cin >> Q;
    while (Q--) {
        cin >> l >> r;
        LL ans = 0, m = 0;
        FOR (i, 0, 26) c[i] = a[r][i] - a[l - 1][i];
        FOR (i, 0, 26) {
            m += c[i] / 2;
            if (c[i] & 1) ans++;
        }
        if (ans == 0) ans = 1;
        ans = ans * fac[m] % MOD;
        FOR (i, 0, 26) {
            LL t = c[i] / 2;
            if (t) ans = ans * invf[t] % MOD;
        }
        cout << ans << endl;
    }
}