n,q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
r = []
l = []
q.times do |i|
  l[i],r[i] = gets.chomp.split(" ").map(&:to_i)
end
arr = Array.new(n,0)
pre = ""
cnt = 0
n.times do |i|
  if pre == "A" && s[i] == "C"
    cnt += 1
  end
  arr[i] = cnt
  pre = s[i]
end

q.times do |i|
  if l[i] >= 2
    puts arr[r[i]-1] - arr[l[i]-1]
  else
    puts arr[r[i]-1]
  end
end