require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,q = gets.chomp.split.map(&:to_i)
s = gets.chomp

dp = Array.new(n)
dp[0] = 0
1.upto(n-1).each do |i|
  dp[i] = dp[i-1]
  if s[i-1] == 'A' && s[i] == 'C'
    dp[i] += 1
  end
end

q.times do
  l,r = gets.chomp.split.map(&:to_i)
  puts dp[r-1] - dp[l-1]
end


