#!/bin/python import sys import math def initialize(s): # This function is called once before all queries. pass def answerQuery(l, r): # Return the answer for this query modulo 1000000007. lst = [] snew = s[l-1:r] set_s = set(snew) for i in set_s: lst.append(snew.count(i)) num = sum(i%2 for i in lst) length = len(lst) if num > 1: return 0 if num == 1 and length%2 ==0: return 0 if num == 0 and length%2 ==1: return 0 lstnew = [i/2 for i in lst] result1 = math.factorial(sum(lstnew)) for i in lstnew: result1= result1/ math.factorial(i) return (result1%1000000007) 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) print result