n, q = gets.chomp.split.map &:to_i
s = gets.chomp

current = 0

idx = s.size - 2
next_idx = 0

count = []

while (next_idx = s.rindex("AC", idx)) != nil
	count = [current] * (idx - next_idx + 1) + count
	current += 1
	if next_idx >= 1 then
		idx = next_idx - 1
	else
		break
	end
end

if next_idx == 0 then
	count = [current] * idx + count
else
	count = [current] * (idx + 2) + count
end

result = []

q.times{
	l, r = gets.chomp.split.map &:to_i
	result << count[l-1] - count[r-1]
}

result.each { |r|
	puts r
}
