n,q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
sum = [0]
for i in 1...s.length do
    sum[i] = sum[i-1]
    if (s[i-1] + s[i]).eql?('AC') then sum[i]+=1 end
end

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