#include #include int main() { int q,len,l,r,Q[26],t,num2=0,num1=0,sum=0,temp,ans=1,i; char S[100000]; scanf("%s",S); len =strlen(S); scanf("%d",&q); while(q--) { scanf("%d %d",&l,&r); for(i=0;i<26;i++) Q[i] = 0; num2=0; num1=0; ans=1; for(i=l;i<=r;i++) { t = S[i] - 97; Q[t] = Q[t]+1; if(Q[t] > 2) num2++; else num1++; } while(num2 > 0) { ans = ans*num2; num2--; } ans = ans*num1; printf("%d\n",ans/2); } return 0; }