Under construction

Still being built. Things may change

Chain & Co.

Time limit10sMemory limit128 MB

Summary
Decide whether axis-aligned square links split into two nonempty groups with every cross pair linked.
Level

Hard9 of 10

Topics
Geometry, Graph, Intervals
Solved
No attempts yet

Problem

Chain & Co. makes chains that are infinitely strong. The products are good and the market share grows fast, and that brings work nobody at the company had imagined before. One piece of that work is checking automatically, with a computer program, whether a pile of links sits in testing position. You write that program.

Every link the company makes has the same size. One link is an infinitely thin square frame in three dimensions, built from four infinitely thin segments.

During a test all links are axis-aligned and no two frames touch. Axis-aligned means every segment of a link is parallel to the XX, YY, or ZZ axis. A proper strength test needs the links split into two sets AA and BB so that every link of AA is inseparable from every link of BB. Two links are inseparable when you cannot move them apart without breaking one of them.

You are given nn links, all axis-aligned and no two of them touching. Are they in proper testing position? In other words, can all of the given links be divided into two non-empty sets AA and BB with that property?

Input

The first line contains the number of test cases TT. The test cases follow one after another, and each of them is preceded by an empty line.

The line after the empty line contains the number of links in the chain nn (1≤n≤1061 \le n \le 10^6). Each of the next nn lines contains six space separated integers xix_i, yiy_i, ziz_i, xi′x_i', yi′y_i', zi′z_i', all between −109-10^9 and 10910^9, the coordinates of two opposite corners of the ii-th link.

Output

For each test case print one line with the answer. Print YES if the given links are in proper testing position, and NO otherwise.

Examples1

  1. Example 1

    Input
    3
    
    2
    0 0 0 0 10 10
    -5 5 15 5 5 25
    
    5
    0 0 0 0 10 10
    -5 5 6 5 5 16
    -5 5 -6 5 5 4
    -5 6 5 5 16 5
    -5 -6 5 5 4 5
    
    3
    0 0 0 3 0 -3
    1 -1 -1 1 2 -4
    -1 -2 -2 2 1 -2
    
    Expected output
    NO
    YES
    YES