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

dp = Array.new(N + 1, 0)
dp[0] = 0
(1 .. N).each do |i|
  dp[i] = dp[i - 1]
  dp[i] += 1 if i >= 2 && S[i - 2] == 'A' && S[i - 1] == 'C'
end

puts Q.map{|l,r| dp[r] - dp[l] }
