line = gets.chomp!
/(\d+)\s*(\d+)/ =~ line
N = $1.to_i
Q = $2.to_i

S = gets.chomp!

tar=S.split("")
array=[0]

count=0
for cnt in 1..(N-1) do
  if (tar[cnt-1]=='A' and tar[cnt]=='C') then
    count += 1
  end
  array.push(count)
end

for cnt in 1..Q do
  line = gets.chomp!
  /(\d+)\s*(\d+)/ =~ line
  l = $1.to_i 
  r = $2.to_i
  puts array[r-1]-array[l-1]
  
end
