def foo
  i = gets.to_i
  i.times do
    list = gets.split.map(&:to_i)
    res = Array.new(8) do |j|
      a, b, c = list[j], list[j+1], list[j+2]
      a < b || a < c || b < c ? 'YES' : 'NO'
    end
    puts(res.include?('NO') ? 'NO' : 'YES')
  end
end

foo