import sys if sys.version_info[0]<=2: range=xrange input=raw_input M=10**9+7 fact=[0]*100001 fact[0]=1 for i in range(1,100001): fact[i]=(fact[i-1]*i)%M def modinv(x,mod): if mod<0: mod=-mod b0,b1=0,1 r0,r1=mod,x%mod while r1: q=r0//r1 r0,r1=r1,r0-q*r1 b0,b1=b1,(b0-q*b1)%mod if r0==1: return b0 return None def solve0(arr,n,m): al,ar=arr[n-1],arr[m] num,den=0,1 odds=0 for i in range(26): dif=ar[i]-al[i] odds+=dif&1 even=dif//2 num+=even den=(den*fact[even])%M num=fact[num] num=(num*modinv(den,M))%M return (odds*num)%M if odds else num word=input().strip() l=len(word) arr=[None]*(l+1) arr[0]=[0]*26 for i in range(l): c=word[i] arr[i+1]=arr[i][:] arr[i+1][ord(c)-ord("a")]+=1 cases=int(input().strip()) for cs in range(1,cases+1): n,m=map(int,input().strip().split()) print(solve0(arr,n,m))