num = STDIN.gets.to_i
for i in 0.. num-1
  data = STDIN.gets.split(/ /)
  for i in 0.. data.length-1
    data[i] = data[i].to_i
  end
  a = Array.new
  b = [0]
  a.push(data.shift)
  for i in 0.. data.length-1
    if data[0] > a[a.length-1]
      a.push(data.shift)
    else
      if data[0] > b[b.length-1]
        b.push(data.shift)
      else
        puts "NO"
        break
      end
    end
  end
  if data.length == 0
    puts "YES"
  end
end