#include #include #include #include #include #include using namespace std; typedef long long ll; const int maxn = 1e5 + 7; const ll md = 1e9 + 7; int a[30][maxn]; ll f[maxn]; ll fi[maxn]; ll modinv(ll x) { ll ans = 1, ex = md - 2; while (ex > 0) { if ((ex%2ll) == 1) { ans = (ans * x)%md; } x = (x * x)%md; ex = ex / 2; } return ans; } int main() { f[0] = 1ll; fi[0] = 1ll; for (int i = 1; i < maxn; i++) { f[i] = (f[i - 1] * i)%md; fi[i] = modinv(f[i]); } string s; cin>>s; int n = s.size(); s = " " + s; int q; cin>>q; for (int j = 0; j < 30; j++) a[j][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 30; j++) a[j][i] = a[j][i - 1]; a[s[i] - 'a'][i]++; } while (q--) { int l, r; cin>>l>>r; int ev = 0, od = 0; ll ans = 1; int s = 0; for (int i = 0; i <= 'z' - 'a'; i++) { int v = a[i][r] - a[i][l - 1]; //cout<<(char)('a' + i)<<":"<