ar = gets.chomp.split(" ").map{|i|i = i.to_i}
n = ar[0]
q = ar[1]

s = gets.chomp!
arr = []
q.times{
    arr << gets.chomp.split(" ").map{|i|i = i.to_i}
}
arr.each{|a|
    pos=0
    flag=0
    count=0
    now_count=0
    #pp a
    #puts s.slice( (a[0]-1)..(a[1]-1) )
    s.slice((a[0]-1)..(a[1]-1)).chars{|c|
        #puts "adflkjasd"
        if c=="A" then
            flag=1
        elsif c=="C" && flag==1 then
            count+=1
            flag=0
        end
        pos+=1
    }
    puts count
}

