def start(a):
    global word
    k = 1
    for s in range (a[0],a[1]-1):
        if word[s] > word[s+1]:
            k = k +1
    print(k)

word = input()
for i in range(int(input())): start(list(map(int, input().split())))
    