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

point = []

i = 0
while i < N - 1 do
  if S[i...i + 2] == 'AC'
    point << i
    i += 1
  end
  i += 1
end

Q.times do
  l = gets.split.map(&:to_i)
  result = 0
  i1 = -1
  point.each_with_index do |p, i|
    if p >= l[0] - 1
      i1 = i
      break
    end
  end

  ii = i1
  while ii < point.size
    if point[ii] >= l[1] - 1
      break
    end

    ii += 1
  end
  puts ii - i1
end
