#include #define MAX 1000001 #define M 1000000007 #define ll long long #define ld long double using namespace std; string s; ll pre[26][MAX]; ll f[MAX]; ll exp(ll a, ll b) { if (!b) return 1; if (b&1) return (a*exp(a, b-1))%M; ll p = exp(a, b/2); return (p*p)%M; } int main() { f[0] = 1; for (int i=1;i> s; int ln = s.length(); for (int i=0;i> q; while(q--) { ll x, y; scanf("%lld%lld", &x, &y); ll cn[26]; ll odd = 0; ll sum = 0; for (int i=0;i<26;i++) { cn[i] = pre[i][y]-pre[i][x-1]; odd+=cn[i]%2; cn[i]/=2; sum+=cn[i]; } if (!odd) odd++; ll res = 1; ll num = f[sum]; ll den = 1; for (int i=0;i<26;i++) { den = (den*f[cn[i]])%M; } // cout << num << " " << den << " " << odd << endl; res = (num*exp(den, M-2))%M; printf("%lld\n", (res*odd)%M); } return 0; }