s=input()
prbl=[]

for i in range(1,len(s)):
    if s[i] == "b" and s[i-1]=="c":
        prbl.append(i)
    elif s[i] =="a" and (s[i-1] in ["b","c"]):
        prbl.append(i)
for i in range(int(input())):
    s,e=map(int,input().split())
    k=0
    for pr in prbl:
        if s<pr<e:
            k+=1
    print(k+1)
