n,q = gets.split.map(&:to_i)
s = gets.chomp.chars
l = []
r = []
q.times do |i|
    l[i],r[i] = gets.split.map(&:to_i)
end
sum = 0
t = []
t[0] = 0
for i in  1..(n-1)
    if s[i-1] == 'A' && s[i] == 'C'
        sum += 1
    end
    t[i] = sum
end
for j in 0..(q-1)
    puts t[r[j]-1]-t[l[j]-1]
end