#include using namespace std; long long mod = 1e9 + 7; int pref[100001][28]; long long f[100001]; long long inv[100001]; long long bp (long long x, long long n) { long long ans = 1; while (n) { if (n & 1) ans = (ans * x) % mod; x = (x * x) % mod; n >>= 1; } return ans; } int main () { ios_base::sync_with_stdio (); cin.tie (0), cout.tie (0); string s; cin >> s; for (int i = 0;i < s.size ();i ++) { for (char x = 'a';x <= 'z';x ++) { pref[i + 1][x - 'a' + 1] = pref[i][x - 'a' + 1]; if (s[i] == x) pref[i + 1][x - 'a' + 1] ++; } } f[0] = 1; inv[0] = 1; for (int i = 1;i <= 100000;i ++) { f[i] = (f[i - 1] * i) % mod; inv[i] = bp (f[i], mod - 2) % mod; } int t; cin >> t; while (t --) { int l, r; cin >> l >> r; long long ans = 0, sum = 0, kol = 0, kol1 = 0; bool ok = 0; for (char x = 'a';x <= 'z';x ++) { if ((pref[r][x - 'a' + 1] - pref[l - 1][x - 'a' + 1]) % 2 == 1) ok = 1; if (pref[r][x - 'a' + 1] - pref[l - 1][x - 'a' + 1] > 1) kol ++; if ((pref[r][x - 'a' + 1] - pref[l - 1][x - 'a' + 1]) % 2 == 1) kol1 ++; sum += (pref[r][x - 'a' + 1] - pref[l - 1][x - 'a' + 1]) / 2; } ans = f[sum]; // cout << ans << ' '; for (int i = 1;i <= 26;i ++) { if ((pref[r][i] - pref[l - 1][i]) / 2 < 1) continue; int x = (pref[r][i] - pref[l - 1][i]) / 2; ans = (ans * inv[x]) % mod; } // cout << ans << ' '; if (ok) { ans = (ans * kol1) % mod; } cout << ans << endl; } return 0; }