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)



'''
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
    for j in wordindexes:
        firstflag = True
        if i[0] <= j <= i[1]:
            count += 1
            if (i[0] < j) and firstflag: 
                count += 1
            firstflag = False
    print(count)
'''


