N, Q = gets.split.map(&:to_i)
S = gets.chomp
LR = Q.times.map { gets.split.map(&:to_i) }

L = 0
R = 1

ac_counts = Array.new(S.size, 0)
1.upto(S.size - 1) do |i|
  if S[i-1] == 'A' && S[i] == 'C'
    ac_counts[i] = ac_counts[i-1] + 1
  else
    ac_counts[i] = ac_counts[i-1]
  end
end

LR.each do |lr|
  puts ac_counts[lr[R]-1] - ac_counts[lr[L]-1]
end
