s=input() q=int(input()) for _ in range(q): l,r=map(int,input().split()) e=0 o=0 a=[0]*125 for i in range(l-1,r): a[ord(s[i])]+=1 for i in range(97,123): if a[i]!=0: if a[i]%2==0: e+=1 else: o+=1 print(e,o) if e==1 and o==0: print(1) else: print(e*o)