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)

# bcaabba
# ye
#  no
#   ye
#    ye
#     ye
#      no
# bcaabba
# bc aabb a

# abcaabbaccccb
# ye
#  ye
#   no
#    ye
#     ye
#      ye
#       no

# abcaabbaccccb
# abc aabb acccc b