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

lr = []
for i in range(q):
    lr.append(list(map(int, input().split())))
amt = []

for i in range(q):
    words = 0
    start, stop = lr[i][0] - 1, lr[i][1] - 1
    ind = start
    while ind < stop:
        char = s[ind]
        next_char = s[ind + 1]
        if char == "b":
            if next_char == "a":
                words += 1
        elif char == "c":
            if next_char != "c":
                words += 1
        ind += 1
    amt.append(words + 1)

for w in amt:
    print(w)
