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

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

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

for w in amt:
    print(w)
