n,q = gets.split(' ').map &:to_i
s = gets.chop.split('')
pre = ''
arr = []
point = 0
s.each_with_index do |t, i|
  point += 1 if pre == 'A' && t == 'C'
  arr[i] = point
  pre = t
end
p arr
q.times {
  l,r = gets.split(' ').map &:to_i
  p arr[r-1] - arr[l-1]
}
