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