n, q = gets.split.map(&:to_i)
s = gets.chomp
ans = 0
dp = Array.new(n,0)
for i in 0..s.size-1 do
  dp[i] = dp[i-1].to_i
  if s[i..i+1] == 'AC'
    dp[i] += 1
  end
end

q.times do |i|
  l, r = gets.split.map(&:to_i)
  lt = l < 2 ? 0 : dp[l-2]
  puts dp[r-2] - lt
end
