#include #define mod 1000000007 using namespace std; long long pwr (long long base,long long exp) { long long res; res = 1LL; while (exp > 0) { if (exp % 2 == 1) { res = (res * base) % mod; } base = (base * base) % mod; exp = exp / 2; } return res; } long long fact[1000005], n, pre[100005][30], flag, odc, a[30], mx, num, den, ans, q, l, r; char s[100005]; void pre_compute (){ fact[1] = 1; fact[0] = 1; for (int i = 2 ; i <= 1000000 ; i++) fact[i] = ((fact[i-1]%mod)*i)%mod; } int main () { pre_compute(); cin >> (s+1); n = strlen(s+1); //cout << n << endl; for (int i = 1 ; i <= n ; i++) { for (int j = 0 ; j < 26 ; j++) { pre[i][j] = pre[i-1][j] + (j == (s[i]-'a')); } } cin >> q; while (q--) { cin >> l >> r; flag = 0; odc = 0; mx = 0; num = 0; for (int i = 0 ; i < 26 ; i++) { a[i] = pre[r][i] - pre[l-1][i]; if (a[i]&1) flag = 1, odc++; mx = mx + 2*(a[i]/2); } mx += flag; //cout << "len is " << mx << endl; if (mx == 1) { cout << odc << endl; } else if (mx&1) { den = 1LL; for (int i = 0 ; i < 26 ; i++) { num += a[i]/2; //den = (den*fact[a[i]/2])%mod; } ans = fact[num]; for (int i = 0 ; i < 26 ; i++) { ans = (ans*pwr(fact[a[i]/2], mod-2))%mod; } //ans = (num*pwr(den, mod-2))%mod; ans = (ans*odc)%mod; cout << ans << endl; } else { den = 1LL; for (int i = 0 ; i < 26 ; i++) { num += a[i]/2; //den = (den*fact[a[i]/2])%mod; } ans = fact[num]; for (int i = 0 ; i < 26 ; i++) { ans = (ans*pwr(fact[a[i]/2], mod-2))%mod; } //ans = (num*pwr(den, mod-2))%mod; cout << ans << endl; } } return 0; }