uses math; const base=round(1e9+7); var s:ansistring; i,q,l,r:longint; cnt1,cnt2,cnt3:int64; c:char; cnt:array[0..100000,'a'..'z']of int64; factorial:array[0..100000]of int64; function power(a,b:int64):int64; begin if b=0 then exit(1); power:=power(a,b>>1); power:=power*power mod base; if odd(b) then power:=power*a mod base end; begin read(s,q); factorial[0]:=1; for i:=1 to length(s) do factorial[i]:=factorial[i-1]*i mod base; for c:='a' to 'z' do for i:=1 to length(s) do cnt[i][c]:=cnt[i-1][c] + ord(s[i]=c); for q:=1 to q do begin read(l,r); cnt1:=0; cnt2:=0; cnt3:=1; for c:='a' to 'z' do begin i:=cnt[r][c]-cnt[l-1][c]; cnt1:=cnt1+(i and 1); cnt2:=(cnt2+i>>1) mod base; cnt3:=cnt3*factorial[i>>1] mod base end; cnt1:=max(cnt1,1); writeln((cnt1*factorial[cnt2] mod base)*power(cnt3,base-2) mod base) end end.