len, qs = gets.split.map(&:to_i)
a = false
is_ac = gets.chomp.chars.each_with_index.map{|char, i|
    ac = 0
    if a && char == 'C'
        ac = 1
    end
    a = char == 'A'
    ac
}[1..-1]
sums = is_ac.inject([0]){|acc, it| acc + [acc[-1] + it]}

qs.times{|it|
    s, e = gets.split.map(&:to_i)
    puts sums[e - 1] - sums[s - 1]
}
