n,q=gets.split.map &:to_i
s=gets.chomp.chars.each_cons(2).map{|x| x=(x==["A","C"])? 1:nil}
x=[]
y=[]
q.times do |i|
  x[i],y[i]=gets.split.map &:to_i
end
q.times do |j|
  puts s.slice(x[j]-1..y[j]-2).compact.size
end
