s = input()
a = [0] * (len(s))
for i in range(len(s)):
    if s[i] == 'a':
        a[i] = 1
    elif s[i] == 'b':
        a[i] = 2
    elif s[i] == 'c':
        a[i] = 3
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[i] > a[i+1]:
            k += 1
    return k+1

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


