a = str(input())
n = int(input())

res = 0
for i in range(n):
	a1, b1 = map(int, input().split())
	f = a[a1-1:b1]
	res += sum([f.count("ba"), f.count("cb"), f.count("ca")])

	print(res+1) if res != 0 else print(1)
	res = 0
