N, Q = gets.chomp.split(" ").map{|s| s.to_i }
S = gets.chomp

q_arr = []
Q.times do |i|
  q_arr << gets.chomp.split(" ").map{|s| s.to_i }
end

iarr = []
(N-1).times do |i|
  iarr << i+1 if S[i..(i+1)] == "AC"
end

q_arr.each do |l, r|
  lind = 0
  rind = 0
  iarr.each_with_index do |n, i|
    if l <= n
      lind = i-1
      break
    end
  end
  iarr.each_with_index.reverse_each do |n, i|
    if r > n
      rind = i
      break
    end
  end

  puts rind-lind
end
