s = input()
s1=""
n=int(input())
count=1
for i in range(n):
    a,b=map(int, input().split())
    s1=s[a-1:b:]
    count+=s1.count('ca')
    count+=s1.count('cb')
    count+=s1.count('ba')
    print(count)
    count=1
