raw = input()
n = int(input())
for i in range(n):
    raw1 = raw[int(input()):int(input())]
    for j in range(len(raw1)):
        sum = 0
        if (raw1[j] == "b") and (raw[j+1] == "a"):
            sum += 1
        elif (raw1[j] == "c") and (raw[j+1] == "b" or raw[j+1] == "a"):
            sum += 1
        print(sum)
            
    