s = input()
a = ""
for x in s:
    if x == "a":
        a+="1"
    elif x == "b":
        a+='2'
    elif x == "c":
        a+="3"
q = int(input())
for x in range(q):
    l, r = map(int, input().split())
    o = a[l-1:r]
    p = 0  
    slova = 1
    for y in o:
        if p > int(y):
            slova+=1
        p=int(y)
    print(slova)        