n, q = gets.split.map(&:to_i)
s = gets.chomp

csum = Array.new(n+1, 0)
for i in 0..n - 1
    if i <= n - 2
        if s[i..i+1] == 'AC'
            csum[i+1] += 1
            s[i] = 'a'
        end
    end
    csum[i+1] += csum[i]
end

q.times do
    l, r = gets.split.map(&:to_i)
    l -= 1
    puts csum[r-1] - csum[l]
end
