#encoding:utf-8 No.0033 2014.10.7
n = gets.chomp.to_i
cylinderA = Array.new(n)
judgement = Array.new(n)

n.times do |i|
  cylinderA[i] = gets.chomp.split.map{|item| item.to_i}
  cylinderB = []
  cylinderC = []
  
  cylinderB.push cylinderA[i][0] #まずひとつcylinderBに入れる
  j = 1
  while j < cylinderA[i].length  #cylinderAからひとつずつ落としていく
    if cylinderA[i][j] > cylinderB.last
      cylinderB.push cylinderA[i][j]  #cylinderBには確実に昇順に並ぶ
    else
      cylinderC.push cylinderA[i][j]  #cylinderCには昇順に並ぶとは限らない
    end
    j += 1
  end
  
  if cylinderC == cylinderC.sort
    judgement[i] ="YES"
  else
    judgement[i] ="NO"
  end
end

puts judgement