s=input() q=int(input()) for i in range(q): n=input() n=n.split() l=int(n[0]) u=int(n[1]) l=l-1 u=u-1 f1=0 f2=0 f3=0 c=0 N=0 fact=1 for i in "abcdefghijklmnopqrstuvwxyz": c=s.count(i) if c>1: if c%2==0: f2+=(c//2) else: f3+=1 f1+=((c-1)//2) else: f3+=1 if not(f1>0 or f2>0): print(len(s)) else: N = (f1+f2) fact=1 for j in range(1,N+1): fact = fact*j fact = fact * f3 print(fact%1000000007)