#include using namespace std; const int nmax = 1e5; const int omega = 30; const int mod = 1e9 + 7; int fact[nmax + 1], inv[nmax + 1]; int cnt[omega + 1][nmax + 1]; int lgput (int b, int p) { int ans = 1; while (p > 0) { if (p & 1) ans = 1LL * ans * b % mod; p >>= 1; b = 1LL * b * b % mod; } return ans; } void initialize(string s) { for (int j = 0; j < omega; ++ j) { for (int i = 1; i <= (int)s.size(); ++ i) { cnt[ j ][ i ] = cnt[ j ][i - 1] + (s[i - 1] - 'a' == j); } } fact[ 0 ] = 1; for (int i = 1; i <= nmax; ++ i) { fact[ i ] = 1LL * fact[i - 1] * i % mod; } inv[ nmax ] = lgput(fact[nmax], mod - 2); for (int i = nmax - 1; i >= 0; -- i) { inv[ i ] = 1LL * inv[i + 1] * (i + 1) % mod; } } int answerQuery(int l, int r) { int imp = 0; int ans = 1; int s = 0; for (int i = 0; i < omega; ++ i) { int x = cnt[ i ][ r ] - cnt[ i ][l - 1]; if (x % 2 == 1) { ++ imp; -- x; } x /= 2; s += x; ans = 1LL * ans * inv[ x ] % mod; } ans = 1LL * fact[ s ] * ans % mod; if (imp == 0) imp = 1; ans = 1LL * ans * imp % mod; return ans; } 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; }