#!/bin/python import sys from itertools import permutations #def initialize(s): # This function is called once before all queries. def answerQuery(l, r): s1=s[l:r] leng=r-l+1 max_l=0 while(leng>0): p=list(permutations(s1,leng)) c=0 for i in range(0,len(p)): s2=p[i] if(s2==s2[::-1]): max_l=leng c+=1 if(c>0): return c leng-=1 # Return the answer for this query modulo 1000000007. if __name__ == "__main__": s = raw_input().strip() #initialize(s) q = int(raw_input().strip()) for a0 in xrange(q): l, r = map(int,raw_input().strip().split(' ')) #l, r = [int(l), int(r)] result = answerQuery(l, r) print result