// In search of the sexy lady #include #define LL long long using namespace std; #define INF 1000000000000 #define MOD 1000000007 #define sf scanf #define pf printf #define pb push_back #define mp make_pair #define ff first #define ss second #define ABS(x) ((x)<0?-(x):(x)) inline LL gcd ( LL a, LL b ) { a = ABS ( a ); b = ABS ( b ); while ( b ) { a = a % b; swap ( a, b ); } return a; } LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){ LL x2, y2, x1, y1, x, y, r2, r1, q, r; x2 = 1; y2 = 0; x1 = 0; y1 = 1; for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) { q = r2 / r1; r = r2 % r1; x = x2 - (q * x1); y = y2 - (q * y1); } *X = x2; *Y = y2; return r2; } inline LL modInv ( LL a, LL m ) { LL x, y; ext_gcd( a, m, &x, &y ); x %= m; if ( x < 0 ) x += m; return x; } inline LL power ( LL a, LL p ) { LL res = 1, x = a; while ( p ) { if ( p & 1 ) res = ( res * x ); x = ( x * x ); p >>= 1; } return res; } inline LL bigmod ( LL a, LL p, LL m ) { LL res = 1 % m, x = a % m; while ( p ) { if ( p & 1 ) res = ( res * x ) % m; x = ( x * x ) % m; p >>= 1; } return res; } #define MX 322222 char s[MX]; int n,q,l,r; LL a[26][MX]; bool fndcenter; LL dd,ss, deno, nume; int charID(char p) { return (int)(p-'a'); } LL fact[MX], cnt; int main() { // freopen("in.txt", "r", stdin); fact[0]=1; for(LL i = 1; i < MX; i ++) fact[i] = (fact[i-1]*i)%MOD; sf("%s", s); sf("%d", &q); n = strlen(s); for(int i = 1;i <=n;i ++) { for(int j = 0 ; j < 26;j++) { a[j][i] = a[j][i-1]; } a[charID(s[i-1])][i] ++; } while(q--) { sf("%d %d",&l, &r); dd = 0; ss = 0; deno = 1; for(int j = 0; j < 26; j ++ ) { cnt = a[j][r] - a[j][l-1]; deno = (deno * modInv(fact[cnt/2],MOD)) % MOD; dd += cnt / 2; ss += cnt % 2; } //cout<<"dd:"<