#!/bin/python import sys #def initialize(s): # This function is called once before all queries. def answerQuery(l, r,s): inString = s[l-1:l-1+r] count = [] ascChr = 97 oddCount = 0 evenCount = 0 answer = 1 for i in range(25): count.append(0) count[i] = inString.count(chr(ascChr)) ascChr = ascChr + 1 if count[i] % 2 == 0: evenCount = count[i] / 2 + evenCount answer = answer / factorial(count[i] / 2) else: oddCount = oddCount + 1 if oddCount == 0: oddCount = 1 return (factorial(evenCount) * answer * oddCount) % (10**9 + 7) # Return the answer for this query modulo 1000000007. def factorial(n): num = 1 while n >= 1: num = num * n n = n - 1 return num if __name__ == "__main__": s = raw_input().strip() #initialize(s) q = int(raw_input().strip()) for a0 in xrange(q): l, r = raw_input().strip().split(' ') l, r = [int(l), int(r)] result = answerQuery(l, r, s) print result