s = input()
n = int(input())
for i in range(n):
    c = 1
    a, b = map(int, input().split())
    v = s[a - 1:b]
    for j in range(1, len(v)):
        if v[j - 1] == 'b' and v[j] == 'a':
            c += 1
        elif v[j - 1] == 'c' and v[j] == 'a':
            c += 1
        elif v[j - 1] == 'c' and v[j] == 'b':
            c += 1
    print(c)
