num = gets.to_i
num.times do
  b, c = [], []
  a = gets.chomp.split(' ').map(&:to_i)
  a.each do |i|
    if (b.last||0) < i
      b << i
    elsif (c.last||0) < i
      c << i
    else
      break
    end
  end
  puts (a.size==b.size+c.size) ? 'YES' : 'NO'
end