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