#!/bin/python3 import sys def initialize(s): # This function is called once before all queries. pass def answerQuery(s, l, r): # Return the answer for this query modulo 1000000007. target = s[l-1:r] dict = {} for char in target: if char in dict: dict[char] += 1 else: dict[char] = 1 even = [v for v in dict.values() if v % 2 ==0] odd = [v for v in dict.values() if v % 2 !=0] oddCount = 1 if len(odd) > 0: oddCount = len(odd) return (len(even)*oddCount) % 1000000007 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(s, l, r) print(result)