n = readline.chomp.to_i
n.times{
  v = readline.chomp.split.map{|c| c.to_i}

# (1..10).to_a.permutation{|v|
  # p v
  stack1 = [0]
  stack2 = [0]

  v.each{|c|
    if stack1[-1] < c
      stack1.push(c)
    elsif stack2[-1] < c
      stack2.push(c)
    else
      puts "NO"
      break
    end
    # if stack1[-1] > stack2[-1]
    #   if stack1[-1] < c
    #     stack1.push(c)
    #   elsif stack2[-1] < c
    #     stack2.push(c)
    #   else
    #     puts "NO"
    #     break
    #   end
    # else
    #   if stack2[-1] < c
    #     stack2.push(c)
    #   elsif stack1[-1] < c
    #     stack1.push(c)
    #   else
    #     puts "NO"
    #     break
    #   end
    # end
  }
  if stack1.size + stack2.size == 12
    puts "YES"
  end
  # p stack1
  # p stack2
}