def check(b, c, rest)
  if rest.size == 1
    return b.last < rest.first || c.last < rest.first
  end

  if b.last < rest.first
    bb = b.dup
    rr = rest.dup
    bb.push(rr.shift)
    return true if check(bb, c.dup, rr)
  end
  if c.last < rest.first
    cc = c.dup
    rr = rest.dup
    cc.push(rr.shift)
    return true if check(b.dup, cc, rr)
  end
end

n = gets.to_i
n.times do
  rest = gets.strip.split.map(&:to_i)
  b = [0]
  c = [0]
  b.push(rest.shift)
  puts check(b, c, rest) ? 'YES' : 'NO'
end

