ary = Array.new
while line = $stdin.gets
ary << line.chomp.split
end
ary.delete_at(0)
moji = ary[0][0]

ary.delete_at(0)

ary.each{|item|
a=item[0].to_i-1
b=item[1].to_i-1
puts moji.slice(a..b).scan(/AC/).size
}