#coding: utf-8

num = gets.to_i

num.times do
	b,c = [], []
	data = gets.chomp.split(' ').map(&:to_i)

	data.each do |a|
		if (b.last || 0) < a then
			b << a
		elsif (c.last || 0) < a then
			c << a
		else
			break
		end
	end

	puts (data.size == (b.size + c.size)) ? "YES" : "NO"
end