#!/bin/python3 import sys import itertools st = '' def initialize(s): # This function is called once before all queries. global st st = s def answerQuery(l, r): sub = st[l-1:r+1] maxl = 0 for i in range(len(sub)): com = itertools.combinations(sub,i+1) for a in com: b = list(a) b.reverse() if list(a) == b and i+1>maxl: maxl = i+1 # Return the answer for this query modulo 1000000007. return maxl+1 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)