gets.to_i.times do
  arr = gets.split(" ").map(&:to_i)
  first, second = 0, 0
  i = 0
  while i < arr.length and (arr[i] > first or arr[i] > second)
    if arr[i] < first
      second = arr[i]
    elsif arr[i] < second
      first = arr[i]
    else
      if first < second
        second = arr[i]
      else
        first = arr[i]
      end
    end
    i += 1
  end
  if i == arr.length
    puts "YES"
  else
    puts "NO"
  end
end