#!/bin/python3 import sys from itertools import permutations as perms #def initialize(s): # This function is called once before all queries. def answerQuery(l, r): ans=[] for i in range(r-l): #l=perms(s[i:r]) #print(l) for p in perms(s[l-1:l+i]): #print(p) if p==p[::-1]: ans.append(''.join(p)) maxlength=0 for a in ans: if len(a)>maxlength: maxlength=len(a) count=0 for a in ans: if len(a)==maxlength: count+=1 return count%10**9 # 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) print(result)