require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

N, Q = gets_i_list
S = gets_s

ac_indexes = []
0.upto(N-2) do |i|
  ac_indexes.push(i) if S[i] == "A" && S[i+1] == "C"
end

Q.times do
  if ac_indexes.empty?
    puts 0
    next
  end
  l, r = gets_i_list
  l -= 1
  r -= 1

  l_index = ac_indexes.bsearch_index do |x|
    x >= l
  end

  r_index = ac_indexes.reverse.bsearch_index do |x|
    x > r - 1
  end

  dpp [l_index, r_index]

  l_index = ac_indexes.size - 1 if l_index.nil?
  r_index = ac_indexes.size - 1 if r_index.nil?

  puts r_index - l_index + 1
end