def nb(a,b,c)
  return true if a.length == 0
  p = a.pop
  if b[-1] < p
    b << p
    nb(a,b,c)
  elsif c[-1] < p
    c << p
    nb(a,b,c)
  else
    return false
  end
end
gets.to_i.times do
  a = gets.split.map(&:to_i).reverse
  b = Array.new(1,a.pop)
  c = Array.new(1,0)
  puts nb(a,b,c) ? "YES" : "NO"
end