You've got a string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ |*s*|). The answer to the query is the number of substrings of string *s*[*l*<sub class="lower-index">*i*</sub>... *r*<sub class="lower-index">*i*</sub>], which are palindromes.

String *s*[*l*... *r*] = *s*<sub class="lower-index">*l*</sub>*s*<sub class="lower-index">*l* + 1</sub>... *s*<sub class="lower-index">*r*</sub> (1 ≤ *l* ≤ *r* ≤ |*s*|) is a substring of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub>.

String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">|*t*|</sub> = *t*<sub class="lower-index">|*t*|</sub>*t*<sub class="lower-index">|*t*| - 1</sub>... *t*<sub class="lower-index">1</sub>.
The first line contains string *s* (1 ≤ |*s*| ≤ 5000). The second line contains a single integer *q* (1 ≤ *q* ≤ 10<sup class="upper-index">6</sup>) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ |*s*|) — the description of the *i*-th query.

It is guaranteed that the given string consists only of lowercase English letters.
s=input()
n=len(s)
mark=[]
dp=[] 
for i in range(n):
	mark.append([0]*n)
	dp.append([0]*n)

for i in range(0,n):
	for j in range(0,n):
		if i+j>=n or i-j<0 :break
		if s[i-j]==s[i+j]:
			print(i-j,' ',i+j)
			mark[i-j][i+j]=1
		else : break
	for j in range(1,n):
		if i+j>=n or i-j+1<0:break
		if s[i-j+1]==s[i+j]:
			print(i-j+1,' ',i+j)
			mark[i-j+1][i+j]=1
		else : break 
for i in range(n-1,-1,-1):
	dp[i][i]=1
	for j in range(i+1,n,1):
		dp[i][j]=dp[i+1][j]+dp[i][j-1]+mark[i][j]
		if i+1<=j-1:dp[i][j]-=dp[i+1][j-1]
for i in range(0,n):
	print(dp[i])
q=int(input())
while q>0:
	q-=1
	A=list(map(int,input().split()))
	A[0]-=1
	A[1]-=1
	print(dp[A[0]][A[1]])
