n, q = gets.chomp.split.map(&:to_i)
s = gets
result = []
q.times do |hoge|
    l, r = gets.chomp.split.map(&:to_i)
    bubun = s[(l - 1)..(r - 1)]
    result[hoge] = bubun.scan('AC').size
end

q.times do |hoge|
    puts result[hoge]
end