s = input()
a = ['a','b','c']
q = int(input())
l = [0] * (q)
r = [0] * (q)
for i in range(q):
    l[i], r[i] = map(int,input().split())

def slovo(x,y):
    k = 0
    for i in range(x-1,y-1):
        if a.index(s[i]) > a.index(s[i+1]):
            k += 1
    return k+1

for j in range(q):
    print(slovo(l[j],r[j]))


