n, q = gets.split.map(&:to_i)
s = gets.chomp
lr = q.times.map { gets.split.map(&:to_i) }
prev = ""
arr = Array.new(n, 0)
sum = 0
(0..n-1).each do |i|
  if prev == "A" && s[i] == "C"
    sum += 1
  end
  arr[i] = sum
  prev = s[i]
end
puts lr.map{ |m| arr[m[1]-1] - arr[m[0]-1] }
