n,q=gets.chomp.split.map(&:to_i)
s=gets.chomp.gsub(/AC/, "Ac")
que,r=[],[0]
q.times{que<< gets.chomp.split.map(&:to_i)}
s.size.times{|i|
  s[i]=="c"?r<< r[i-1]+1:r<< r[i-1]
  r.shift if i==0
}
q.times{|a|p (r[que[a][1]-1]-r[que[a][0]-1])}