STDIN.gets
s=STDIN.gets.chomp
a=[0] + [s[0..-2],s[1..-1]].map(&:chars).transpose.map(&:join).map{|x| x == "AC" ? 1 : 0}.inject([]) {|x,y| x+[(x.last||0) + y]}
while t=STDIN.gets
  l,r=t.split.map(&:to_i)
  puts a[r-1] - a[l-1]
end
