#include <bits/stdc++.h>

using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int fac[N], ni[N];
void add(int& a, int b) {
    a += b;
    if (a >= MOD) a-= MOD;
}
int pw(int a, int b) {
    int res = 1;
    for (; b; a = 1ll * a * a % MOD, b >>= 1) {
        if (b & 1) res = 1ll * res * a % MOD;
    }
    return res;
}

int C(int n, int m) {
    return 1ll * fac[n] * ni[n - m] % MOD * ni[m] % MOD;
}
int sum[26][N];

void initialize(string s) {
    // This function is called once before all queries.
    fac[0] = 1;
    ni[0] = 1;
    for (int i = 1; i < N; i++) {
        fac[i] = 1ll * fac[i - 1] * i % MOD;
        ni[i] = pw(fac[i], MOD - 2);
    }
    
    memset(sum, 0, sizeof sum);
    int n = s.size();
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 26; j++) {
            sum[j][i] = sum[j][i - 1];
        }
        sum[s[i - 1] - 'a'][i]++;
    }
}

int answerQuery(int l, int r) {
    // Return the answer for this query modulo 1000000007.
    int single = 0;
    int x;
    vector<int> t;
    int tot = 0;
    for (int i = 0; i < 26; i++) {
        x = sum[i][r] - sum[i][l - 1];
        if (x & 1) {
            single++;
        }
        
        x /= 2;
        if (x) t.push_back(x);
        tot += x;
    }
    
    int res = max(single, 1);
    for (auto v : t) {
        res = 1ll * res * C(tot, v) % MOD;
        tot -= v;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    initialize(s);
    int q;
    cin >> q;
    for(int a0 = 0; a0 < q; a0++){
        int l;
        int r;
        cin >> l >> r;
        int result = answerQuery(l, r);
        cout << result << endl;
    }
    return 0;
}