#include using namespace std; typedef long long ll; typedef long double ld; const int MX = 100 * 1000 + 7; const int MOD = 1000 * 1000 * 1000 + 7; const int AL = 26; int ps[MX][AL]; int pw(int x, int y) { if (y == 0) return 1; if (y % 2 == 0) { return pw(1LL * x * x % MOD, y / 2); } else { return 1LL * pw(x, y - 1) * x % MOD; } } int inv(int x) { return pw(x, MOD - 2); } int fc[MX], rfc[MX]; int calc(const vector &a) { int sm = 0; for (int x : a) sm += x; int ans = fc[sm]; for (int x : a) { ans = 1LL * ans * rfc[x] % MOD; } return ans; } int main() { #ifdef AZINO777 freopen("in", "r", stdin); #endif ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr); string s; cin >> s; int n = s.length(); for (int i = 1; i <= n; i++) { int x = s[i - 1] - 'a'; for (int j = 0; j < AL; j++) { ps[i][j] = ps[i - 1][j]; } ps[i][x]++; } fc[0] = 1; for (int i = 1; i < MX; i++) { fc[i] = 1LL * fc[i - 1] * i % MOD; } for (int i = 0; i < MX; i++) { rfc[i] = inv(fc[i]); } int q; cin >> q; for (int qq = 0; qq < q; qq++) { int l, r; cin >> l >> r; vector go; int ml = 0; for (int i = 0; i < AL; i++) { int v = ps[r][i] - ps[l - 1][i]; if (v) { // cerr << char(i + 'a') << " " << v << endl; go.push_back(v / 2); ml += v % 2; } } if (ml == 0) ml = 1; int ans = 1LL * calc(go) * ml % MOD; cout << ans << "\n"; } }