n,q = gets.split.map(&:to_i)
s = gets.chomp
lr = q.times.map { gets.split.map(&:to_i) }
t = Array.new(n+1, 0)
n.times {|i|
  t[i+1] = t[i] + (s[i..i+1] == 'AC'? 1 : 0)
}
q.times {|i|
  l,r = lr[i]
  puts t[r-1] - t[l-1]
}