#!/bin/python3 from math import factorial from math import pow import sys li = {} mod = pow(10, 9)+7 def initialize(s): # This function is called once before all queries. for c in s: if c in li.keys(): li[c] = li[c]+1 else: li[c] = 1 def multiples(l, m): multiple = 0 for i in l: if i%m==0: multiple+=1 return multiple def answerQuery(l, r): # Return the answer for this query modulo 1000000007. lis = {} for c in s[l:r]: if c in lis.keys(): lis[c] = lis[c]+1 else: lis[c] = 1 twos = 0 ones = 0 for i in lis: if i == 2: twos+=1 else: ones+=1 res = (factorial(twos)%mod)*(ones)%mod for i in range(4, len(s[l:r])+1,2): dups = multiples(lis, i) i = i/2 if dups!=0: res = res/pow(factorial(i), dups) return int(res) if __name__ == "__main__": s = input().strip() 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)