N, Q = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp
LR = []
Q.times{
  LR << gets.chomp.split(" ").map(&:to_i)
}

AC = Array.new(N, 0)
wk = 0
(1...N).each{|i|
  wk += 1 if S[i] == 'C' && S[i-1] == 'A'
  AC[i] = wk
}

LR.each{|l, r|
  puts AC[r-1] - AC[l-1]
}
