/* Problem Link : */ /* herambpatil98 */ #include #define MOD 1000000007 using namespace std; typedef long long ll; ll fact(ll x){ if(x <= 1) return 1; return x * fact(x - 1); } int main(int argc, char const *argv[]) { char s[100005]; cin>>s; int q; cin>>q; while(q--){ ll l, r, len, i; char temp[100005]; strcpy(temp, ""); scanf("%lld %lld", &l, &r); len = r - l + 1; char st[100005]; strcpy(st, s); strncpy(temp, st + l - 1, len); //printf("%s\n", st); strcat(temp, ""); //printf("%lld\n", len); sort(temp, temp + len); ll even, odd, ans; even = odd = 0; ll count = 1; ll t = 1; if(len == 1) odd = 1; for(i = 1; i < len; i++){ if(temp[i] == temp[i - 1]) count++; else{ if(count % 2 == 1) odd++; even += (count / 2); t *= (fact(count / 2)); count = 1; } } if(count % 2 == 1) odd++; even += (count / 2); t *= (fact(count / 2)); //ll t; ans = (ll)fact(even) / t; ans *= max(odd, 1ll); printf("%lld\n", ans); } return 0; }