#include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string str; cin>>str; int len=str.length(); long long int fact[len+1]; fact[0]=1; for(int i=1;i<=len+1;i++) fact[i]=fact[i-1]*i; int q,l,r; cin>>q; while(q--) { cin>>l>>r; int alpha[27] = {0}; int evAlpha[27]={0}; int oddcount=0; int evcount=0; for(int i=l;i<=r;i++) alpha[str[i]-'a']++; int total; for(int i=0;i<=26;i++) { if(alpha[i]!=0) evcount++; if(alpha[i]%2==1) oddcount++; total*=fact[alpha[i]/2]; } cout<<((int)fact[evcount]/total)*oddcount<