Same Snake

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Consider a 2dgrid. That is, each cell is identified by (i,j). You have received reports of two snakesightings on this grid. You want to check whether they could be partial sightings of the same snake or not.
Each of the snake sightings correspond to a straight, axisparallel line segment in the grid, and the starting and ending cells for each are given to you. Now consider a graph, where each cell in the 2dgrid is a vertex. And there is an edge between 2 vertices if and only if the cells corresponding to these two vertices are consecutive cells in at least one of the two snakes. That is, at least in one of the snakes, when you go from one end point to the other end point, these two cells should occur consecutively.
The two sightings/snakes are said to be same, if both these conditions are satisfied:
 The union of the set of cells in the first snake and the set of cells in the second snake, should form a connected component in this graph.
 No vertex should have degree more than 2 in the graph.
In other words, the induced subgraph on the union set must be a path graph.
Input
 The first line contains a single integer, T, which is the number of testcases. The description of each testcase follows.
 The first line of each testcase contains four integers: X_{11}, Y_{11}, X_{12}, Y_{12}. This represents the fact that the first snake's end points are (X_{11}, Y_{11}) and (X_{12}, Y_{12}).
 The second line of each testcase contains four integers: X_{21}, Y_{21}, X_{22}, Y_{22}. This represents the fact that the second snake's end points are (X_{21}, Y_{21}) and (X_{22}, Y_{22}).
Output
 For each testcase, output "yes" if the snakes are the same, as per the definition given above. Output "no" otherwise.
Constraints
 1 ≤ T ≤ 10^{5}
 10^{9} ≤ X_{ij},Y_{ij} ≤ 10^{9}
 The two end points of every snake is guaranteed to be either on the same row or on the same column. Thus, the snake occupies all the cells between these cells, including the end points.
Example
Input: 4 2 1 8 1 11 1 7 1 2 1 8 1 11 1 9 1 2 1 8 1 3 1 3 2 2 1 8 1 2 1 2 2 Output: yes no no yes
Explanation
In the images, the first snake is red, the second snake is yellow, and the intersections, if any, are in orange.
The first test case corresponds to:
Both the conditions on the graph are satisfied, and hence this is a "yes".
The second test case corresponds to:
There is no edge between the vertex corresponding to the (8,1) cell and the vertex corresponding to (9,1), Hence, the union set is disconnected, and thus the answer is "no".
The third test case corresponds to:
The vertex corresponding to the cell (3,1) has degree 3, which is more than 2, and thus the answer is "no".
The fourth test case corresponds to:
Both the conditions on the graph are satisfied, and hence this is a "yes".
Author:  admin3 
Tester:  kingofnumbers 
Editorial  https://discuss.codechef.com/problems/SAMESNAK 
Tags  admin3, easy, grid, implementation, snckql17 
Date Added:  19052017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 