n,q=gets.split.map(&:to_i)
word=gets.chomp.to_s

s=[]
s[0]=0
for i in 0..word.length-1
v=0
if i==0
v=0
elsif word[i-1]=="A" && word[i]=="C"
v=1
end

s[i+1]=s[i]+v
end

q.times.each do
v=gets.split.map(&:to_i)
p s[v[1]]-s[v[0]]
end