len, n = io.read("*n", "*n", "*l")
s = io.read()
pos = 1
t = {}
cur = 0
while(pos <= len) do
    st, lst = string.find(s, "AC", pos)
    if(st == nil) then st = len + 1 end
    for i = pos, st - 1 do
        t[i] = cur
    end
    cur = cur + 1
    t[st] = cur
    pos = st + 1
end
for i = 1, n do
    x, y = io.read("*n", "*n")
    if(x == 1) then
        print(t[y])
    else
        print(t[y-1] - t[x-1])
    end
end