Vivek likes strings a lot but moreover he likes Awesome strings. Vivek calls a string str Awesome if zero or more letters of the string str can be rearranged to form the string "HackerEarth" (case insensitive). For eg : strings HackerEarth , Earthhacker , haeackerrth are all Awesome strings whereas strings HE, Mycareerstack , hackerrearth are not Awesome at all.
Today, Vivek has a special string consisting of both lower case and upper case alphabets letters only. Vivek wants to query this string for the number of Awesome strings.
Each of Vivek's query has the following form L R. For a given query, Vivek wants to count the number of Awesome strings such that starting index S and ending index E of the string follows L ≤ S<E ≤ R.
NOTE
Two strings are considered to be different if either S1 != S2 or E1 != E2 where S1,E1 and S2,E2 are the starting and ending index of string 1 and string 2 respectively. 
Help Vivek accomplishing this task.

Input

First line of the input contains a string S denoting the Vivek's special string. Next line of the input contains a single integer Q denoting the number of Vivek's queries. Next Q lines of the input contains two integers denoting L and R respectively.

Output

For each Vivek's query, print the required answer.

Constraints

1 ≤ |S| ≤ 5x10^5

1 ≤ Q ≤ 5x10^5

1 ≤ L ≤ R ≤ |S|

S belongs to the set of both lower case and upper case alphabets letters only.    
Subtask:
subtask 1 : 1 ≤ N,Q ≤ 10000  : 20 points 

subtask 2 : 1 ≤ N,Q ≤ 10^5  : 20 points

subtask 3 : 1 ≤ N,Q ≤ 5x10^5   : 60 points    
NOTE

 
large input / output data sets, be careful with some languages.

SAMPLE INPUT
HackerEarthhACKEReARTH
5
1 11
2 15
5 15
7 20
7 22

SAMPLE OUTPUT
1
4
1
4
6Explanation

Q1 : "HackerEarth" is the only awesome string.
Q2 : "ackerEarthh","ckerEarthhA","kerEarthhAC","erEarthhACK"  are all awesome strings.
Q3: "erEarthhACK" is the only awesome string.
Q4: "EarthhACKER","arthhACKERe","rthhACKEReA","thhACKEReAR" are all awesome strings.
Q5: "EarthhACKER","arthhACKERe","rthhACKEReA","thhACKEReAR","hhACKEReART","hACKEReARTH" are all awesome strings.
p=[0]*500001
c=[0]*26
t=[0]*26
c[ord('h')-97]=c[ord('a')-97]=c[ord('e')-97]=c[ord('r')-97]=2
c[ord('c')-97]=c[ord('k')-97]=c[ord('t')-97]=1;

s=raw_input().lower()

k=len(s)
if k>10:
	for i in range(11):
		t[ord(s[i])-97]+=1
		if t==c:
			p[10]=1
	for i in range(11,k):
		p[i]=p[i-1]
		if s[i]==s[i-11]:
			if p[i-1]==p[i-2]+1:
				p[i]+=1
		else:
			t[ord(s[i])-97]+=1
			t[ord(s[i-11])-97]-=1
			if t==c:
				p[i]+=1
p[k]=p[k-1]
for q in range(input()):
	i,j=map(int,raw_input().split())
	if j-i>9: print p[j-1]-p[i+8]
	else: print 0