n,q=gets.split.map(&:to_i)
str=gets.chomp.split('')
sumarray=Array.new(n,0)

i=0
(n-1).times{
    if str[i]=="A"&& str[i+1]=="C"
        sumarray[i+1]=sumarray[i]+1
    else
        sumarray[i+1]=sumarray[i]
    end
    i+=1
}

q.times{
    l,r=gets.split.map(&:to_i)
    
    if l==1
        puts sumarray[r-1]
    
    elsif str[l-2]=="A"&& str[l-1]=="C"
        puts sumarray[r-1]-sumarray[l-2]-1
    else
        puts sumarray[r-1]-sumarray[l-2]
    end
    
}