#include using namespace std; typedef long long ll; typedef pair pi; ll mod = 1e9+7; long long fastexp (long long a, long long b, long long n) { long long res = 1; while (b) { if (b & 1) res = res*a%n; a = a*a%n; b >>= 1; } return res; } vector f, ifa; int main() { // clock_t tinici = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); f = vector (1e5+10); ifa = f; f[0] = ifa[0] = 1; for (int i = 1; i < 100005; i++) { f[i] = i*f[i-1]%mod; ifa[i] = fastexp(f[i], mod-2, mod); } string s; cin >> s; int q; cin >> q; int n = s.size(); vector> fr(26, vector (n+1, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { fr[j][i+1] = fr[j][i]; if (s[i]-'a' == j) fr[j][i+1]++; } } while (q--) { int l, r; cin >> l >> r; int let = 0; int odd = 0; ll div = 1; for (int j = 0; j < 26; j++) { int x =fr[j][r] -fr[j][l-1]; if (x%2 == 1) odd++; div = div * ifa[x/2]%mod; let += x/2; } ll res = f[let]*div%mod; if (odd>0) res = res*odd%mod; cout<< res <<"\n"; } return 0; }