s = input();
n = int(input());
c = 0;
l = 0;
r = 0;
for i in range(n):
    l, r = map(int, input().split());
    c = 1;
    for j in range(l - 1, r - 1):
        if s[j:(j + 2)] == "ba" or s[j:(j + 2)] == "ca" or s[j:(j + 2)] == "cb":
            c = c + 1;
    print(c);