a = input()
b = int(input())
k = 0
for i in range(b):
    n1, n2 = map(int, input().split())
    r = 1
    k = 'a'
    for s in list(a[n1-1:n2]):
        if k != s:
            if k == 'a':
                k = s
            elif k == 'b' and s == 'c':
                k = s
            else:
                r = r + 1
                k = s
    print(r)
    r = 0
