N, Q = STDIN.gets.chomp.split(' ').map(&:to_i)
S = STDIN.gets.chomp

ruiseki = Array.new(0)
ruiseki.push(0) # 累積和の一つ目は0
ruiseki.push(0) # 一文字目の分をpush

for i in 1..N do
  if S[i - 1, 2] == "AC" then
    ruiseki.push(ruiseki[i] + 1)
  else
    ruiseki.push(ruiseki[i])
  end
end

for q in 1..Q do
  l, r = STDIN.gets.chomp.split(' ').map(&:to_i)
  puts ruiseki[r] - ruiseki[l]
end