Chain & Co.
Time limit10sMemory limit128 MB
Decide whether axis-aligned square links split into two nonempty groups with every cross pair linked.
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 , , or axis. A proper strength test needs the links split into two sets and so that every link of is inseparable from every link of . Two links are inseparable when you cannot move them apart without breaking one of them.
You are given 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 and with that property?
Input
The first line contains the number of test cases . 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 (). Each of the next lines contains six space separated integers , , , , , , all between and , the coordinates of two opposite corners of the -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.