str1 = input()
n = int(input())
rez = []
num = 0
for i in range(0,n,1):
    first,last = map(int,input().split())
    str2 = str1[first-1:last]
    num += str2.count('ba')
    num += str2.count('cb')
    num += str2.count('ca')
    rez.append(str(num+1))
    num = 0
print('\n'.join(rez))