#!/bin/python import sys from sys import argv def count(l,r,drome): drome=drome[l-1:r-1] total = 0 i = 1 while i <= len(drome): for j in xrange(0, len(drome) - i + 1): if ispalin(drome[j:j+i]): total += 1 i += 1 return total def ispalin(txt): if len(txt) == 1: return False i = 0 j = len(txt) - 1 while i <= j: if txt[i] != txt[j]: return False i += 1 j -= 1 return True if __name__ == "__main__": s = raw_input().strip() q = int(raw_input().strip()) for a0 in xrange(q): l, r = raw_input().strip().split(' ') l, r = [int(l), int(r)] result = count(l, r,s) print result+1