num = gets.to_i
num.times do
  cage1 = Array.new
  cage2 = Array.new
  data = gets.chomp!.split(/\s+/)
  data.size.times do |i|
    data[i] = data[i].to_i
  end
  cage1[0] = data[0]
  cage2[0] = 0
  j = 0
  k = 0
  switch = 0
  (data.size - 1).times do |l|
    if cage1[j] < data[l+1]
      cage1[j+1] = data[l+1]
      j = j + 1
    elsif cage2[0] == 0
      cage2[0] = data[l + 1]
    elsif cage2[k - 1] < data[l+1]
      cage2[k] = data[l+1]
      k = k + 1
    else
    switch = 1
    end
  end
  if switch == 0
    puts "YES"
  else
    puts "NO"
  end
end   