eolymp
bolt
Try our new interface for solving problems
Problems

Chain & Co.

Chain & Co.

Chain & Co. specializes in producing infinitely strong chains. Because of their high quality products, they are quickly gaining market share. This leads to new challenges, some of which they could have never imagined before. Like, for example, automatic verification of link endurance with a computer program, which you are supposed to write. The company produces \textit{links} of equal size. Each link is an infinitely thin square frame in three dimensions (made of four infinitely thin segments). During tests all links are axis-aligned^1 and placed so that no two frames touch. To make a proper strength test, two sets of links \textbf{A} and \textbf{B} are forged so that every link of \textbf{A} is inseparable from every link of \textbf{B} (being inseparable means that they cannot be moved apart without breaking one of them). You stumble upon some links (axis-aligned, pairwise disjoint). Are they in proper testing position? In other words, can they be divided into two non-empty sets \textbf{A} and \textbf{B} with the desired property? ________________________ ^1Axis-aligned means that all segments are parallel to either X, Y, or Z axis. \InputFile The first line contains the number of test cases \textbf{t}. The descriptions of the test cases follow: The description of each test case starts with an empty line. The next line contains an integer \textbf{n }(\textbf{1 }≤ \textbf{n }≤ \textbf{10^6}) - the number of links in the chain. Each of the next \textbf{n }lines contains \textbf{6 }space separated integers \textbf{x_i}, \textbf{y_i}, \textbf{z_i}, \textbf{x'_i}, \textbf{y'_i}, \textbf{z'_i} all between \textbf{-10^9} and \textbf{10^9} - the coordinates of two opposite corners of the \textbf{i}-th link. \OutputFile For each test case, print a single line containing the word \textbf{YES }if the set is in proper testing position, or \textbf{NO }otherwise.
Time limit 1 second
Memory limit 256 MiB
Input example #1
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
Output example #1
NO
YES
YES
Source 2013 ACM ICPC Central Europe Regional Contest, Kraków, November 15-17, Problem H