len, n = io.read("*n", "*n", "*l")
s = io.read()
for i = 1, n do
    x, y = io.read("*n", "*n")
    a = string.sub(s, x, y)
    cnt = 0
    for v in string.gmatch(a, "AC") do cnt = cnt + 1 end
    print(cnt)
end