  1 #coding: utf-8
  2 
  3 num = gets.to_i
  4 
  5 num.times do
  6   b,c = [], []
  7   data = gets.chomp.split(' ').map(&:to_i)
  8 
  9   data.each do |a|
 10     if (b.last || 0) < a then
 11       b << a
 12     elsif (c.last || 0) < a then
 13       c << a
 14     else
 15       break
 16     end
 17   end
 18 
 19   puts (data.size == (b.size + c.size)) ? "YES" : "NO"                           
 20 end