n,q=gets.chomp.split.map(&:to_i)
s=gets.chomp.to_s
que,stat,d=[],false,0
q.times{que<< gets.chomp.split.map(&:to_i)}
q.times{|aa|
  ss= s[que[aa][0]-1,que[aa][1]-que[aa][0]+1].delete("T").delete("G")
  ss.size.times{|aaa|
    stat=true if ss[aaa]=="A"
    if stat==true&&ss[aaa]=="C"
      d+=1;stat=false
    end
  }
  p d
  stat,d=false,0
}