#!/bin/python3 import sys from itertools import permutations def checkP(s): for i in range(len(s)): if s[i] == s[len(s) - i - 1]: continue else: return False return True def initialize(s): # This function is called once before all queries. return None def answerQuery(l, r): # Return the answer for this query modulo 1000000007. sub = s[l : r] com = list(permutations(sub)) sum = 0 for i in range(len(com)): if checkP(com[i]): sum = (sum + 1) % 1000000007 return sum 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)