#!/bin/python3 from itertools import permutations as per s=input() for _ in range(int(input())): l,r = map(int,input().split()) subs = s[l:r+1] perms = [''.join(p) for p in per(subs)] ol=[] for i in perms: if i == i[::-1]: ol.append(len(i)) m = max(ol) print(ol.count(m))