def readList():
    return [int(i) for i in input().split()]

s = input()
q = int(input())
for qq in range(q):
	l, r = readList()
	l -= 1
	r -= 1
	ans = 0
	while l + 1 <= r:
		if s[l] > s[l + 1]:
			#print(s[l], s[l + 1], l)
			ans += 1
		l += 1
	print(ans + 1)