n, q = gets.chomp.split.map(&:to_i)
str = gets.chomp
arr = Array.new(n, false)
(n-1).times do |i|
	arr[i] = true if str[i] == "A" && str[i + 1] == "C"
end
kazu = Array.new(n, 0)
kazu[0] = arr[0] ? -1 : 0
1.upto(n-1) do |i|
	kazu[i] = arr[i] ? -1 * (kazu[i-1].abs + 1)  : kazu[i-1].abs
end
#p arr
#p kazu
q.times do 
	l, r = gets.chomp.split.map(&:to_i).map{|lr| lr - 1}
	ll = kazu[l] 
	rr = kazu[r]
	ll += 1 if ll > 0
	rr += 1 if rr < 0
	puts (rr.abs - ll.abs) + 1
end
