#!/bin/python3 import sys from itertools import permutations def initialize(s): return s # This function is called once before all queries. def get_all_substrings(input_string): length = len(input_string) return [input_string[i:j+1] for i in range(length) for j in range(i,length)] def palindromes(text): results = [] for i in range(len(text)): for j in range(0, i): chunk = text[j:i + 1] if chunk == chunk[::-1]: results.append(chunk) return results def answerQuery(l, r, s): st = s[l-1:r] all_perms = [''.join(p) for p in permutations(st)] all_palindromes = set() for i in all_perms: for p in palindromes(i): all_palindromes.add(p) l_p = list(all_palindromes) k = max(l_p, key=len) return len([i for i in l_p if len(i) == len(k)]) % 1000000007 # Return the answer for this query modulo 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(l, r, s) print(result)