#include <bits/stdc++.h>

using namespace std;

inline int nxt() {
    int x;
    cin >> x;
    return x;
}

const int mod = 1000000007;
const int N = 111111;
int fact[N], inv[N], invfact[N];

int main() {
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    int n = s.size();
    
    fact[0] = invfact[0] = 1;
    for (int i = 1; i < N; ++i) {
        inv[i] = (i == 1) ? 1 : mod - 1ll * mod / i * inv[mod % i] % mod;
        fact[i] = 1ll * fact[i - 1] * i % mod;
        invfact[i] = 1ll * invfact[i - 1] * inv[i] % mod;
    }
    
    array<vector<int>, 26> pref;
    for (int i = 0; i < 26; ++i) {
        pref[i].assign(n + 1, 0);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 26; ++j) {
            pref[j][i + 1] = pref[j][i];
        }
        pref[s[i] - 'a'][i + 1] += 1;
    }
    
    int q = nxt();
    while (q--) {
        int cnt = 0;
        int l = nxt() - 1, r = nxt();
        long long ans = 1;
        int total = 0;
        for (int i = 0; i < 26; ++i) {
            if (pref[i][r] % 2 != pref[i][l] % 2) {
                ++cnt;
            }
            ans = ans * invfact[(pref[i][r] - pref[i][l]) / 2] % mod;
            total += (pref[i][r] - pref[i][l]) / 2;
        }
        ans = ans * fact[total] % mod;
        cout << ans * max(cnt, 1) % mod << "\n";
    }
    
    return 0;
}