def slova(s):
    n = ''
    d = 'abc'
    l = 0
    a = []
    for i in s:
        if n=='':
            n=str(i)
        elif d.index(n[-1])<=d.index(i):
            n+=str(i)
        else:
            a.append(n)
            l +=1
            n = str(i)
    if len(n)!=0:
        l+=1
                
    return l
s = input()
for i in range(int(input())):
    l, r = map(int, input().split())
    print(slova(s[int(l)-1: int(r)]))