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

s = gets.chomp!
arr = []
ac_pos_arr = []
flag=0
count=0
s.length.times{|i|
    if s[i]=="A" && s[i+1]=="C" then
        flag=1
    elsif flag==1 then
        count+=1
        flag=0
    end
    ac_pos_arr << count
}
q.times{
    ar = gets.chomp.split(" ").map{|i|i = i.to_i}
    puts ( ac_pos_arr[ar[1]-1] - ac_pos_arr[ar[0]-1] )
}
