N, Q = gets.split(" ").map(&:to_i)
S= gets.chomp.chars
nums = []
(N - 1).times do |i|
    if S[i] == "A" && S[i + 1] == "C"
        nums << i
    end
end
Q.times do 
    l, r = gets.split(" ").map(&:to_i)
    puts nums.count{|x| (x >= l - 1) && (x < r - 1)}
end
