s = input()
q = int(input())


def split(a, b):
    words = []
    word = ''
    tmp = ''

    for i in range(a-1, b):
        if s[i] == 'a' and (tmp == 'b' or tmp == 'c') or s[i] == 'b' and (tmp == 'c'):
            words.append(word)
            word = s[i]
        else:
            word += s[i]
        tmp = s[i]

    words.append(word)

    return words

arr = []
for i in range(q):
    l, r = map(int, input().split())
    arr.append(len(split(l, r)))
for i in arr:
    print(i)
