words = input()
questions = int(input())
for i in range(questions):
    start, finish = map(int, input().split(" "))
    search = words[start - 1:finish]
    count = 0
    for j in range(len(search) - 1):
        if ord(search[j + 1]) - ord(search[j]) not in (0, 1, 2):
            count += 1
    print(count + 1)


'''
words = input()
questions = int(input())

indexes = [tuple(map(int, input().split(" "))) for _ in range(questions)]

wordindexes = [1]

for j in range(len(words) - 1):
    if ord(words[j + 1]) - ord(words[j]) not in (0, 1, 2):
        wordindexes.append(j + 2)
print(wordindexes)

for i in indexes:
    count = 0
    firstflag = True
    for j in wordindexes:
        if i[0] <= j <= i[1]:
            count += 1
            if (i[0] < j) and firstflag: 
                count += 1
            firstflag = False
    print(count)
'''


