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

num = []
count = 0
S.each do |i|
  if i == "A" && S[count+1] == "C"
    num << 1
    count += 1
  else
    num << 0
    count += 1
  end
end

nums = [0]
sum = 0
num.each do |j|
  sum += j
  nums << sum
end

Q.times do
  l, r = gets.split.map(&:to_i)
  p nums[r-1] - nums[l-1]
end