s = input()
n = int(input())
for i in range(n):
	a,b = input().split()
	a = int(a)
	b = int(b)
	cur = 1
	ts = s[a-1:b]
	#print(ts)
	t = ts.find('ca')
	while t != -1:
		cur+=1
		ts = ts.replace('ca','d',1)
		t = ts.find('ca')
	t = ts.find('cb')
	while t != -1:
		cur+=1
		ts = ts.replace('cb','d',1)
		t = ts.find('cb')
	t = ts.find('ba')
	while t != -1:
		cur+=1
		ts = ts.replace('ba','d',1)
		t = ts.find('ba')
	print(cur)