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