def dfs(balls, i, b, c)
  return true if i == balls.size
  return true if balls[i] > b && dfs(balls, i + 1, balls[i], c)
  return true if balls[i] > c && dfs(balls, i + 1, b, balls[i])
  return false
end

n = gets.to_i
n.times do
  balls = gets.split(' ').map(&:to_i)
  puts dfs(balls, 0, 0, 0) ? 'YES' : 'NO'
end