L, N = gets.split.map(&:to_i)
S = gets.chomp
R = Array.new(N) { gets.split.map(&:to_i) }

As = []
(S.size - 1).times {|i|
  As << i if S[i] == 'A' && S[i + 1] == 'C'
}

R.each {|f, t|
  c = 0
  As.each {|a|
    c += 1 if ((f - 1)..(t - 2)).include? a
  }
  p c
}