#!/bin/python3 import sys import math alphabet="abcdefghijklmnopqrstuvwxyz" def initialize(s): dic=dict() for i in range(25): dic.update({alphabet[i]:0}) lis=[] for i in range(len(s)): dic[s[i]]+=1 lis.append(dic) return lis # This function is called once before all queries. def answerQuery(l, r): counter=[] div=1 n=r-l+1 cc=0 for i in range(25): u=lis[l-1][alphabet[i]]-lis[r-1][alphabet[i]] counter.append(u) if u%2!=0: n-=1 div*=math.factorial(u//2) cc+=1 elif u>0 and u%2==0: div*=math.factorial(u//2) if cc==0: return (math.factorial(n//2)//div)%1000000007 else: return (cc*math.factorial(n//2)//div)%1000000007 # Return the answer for this query modulo 1000000007. if __name__ == "__main__": s = input().strip() lis = initialize(s) q = int(input().strip()) for a0 in range(q): l, r = input().strip().split(' ') l, r = [int(l), int(r)] result = answerQuery(l, r) print(result)