Consider a 2d-grid. That is, each cell is identified by (i,j). You have received reports of two snake-sightings 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, axis-parallel 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 2d-grid 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: X11, Y11, X12, Y12. This represents the fact that the first snake's end points are (X11, Y11) and (X12, Y12).
- The second line of each testcase contains four integers: X21, Y21, X22, Y22. This represents the fact that the second snake's end points are (X21, Y21) and (X22, Y22).

-----Output-----
- For each testcase, output "yes" if the snakes are the same, as per the definition given above. Output "no" otherwise.

-----Constraints-----
- 1 ≤ T ≤ 105
- -109 ≤ Xij,Yij ≤ 109
- 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".

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
t=int(input())
for _ in range(t):
 x1,y1,x2,y2=map(int,input().split())
 x3,y3,x4,y4=map(int,input().split())
 if (x1==x3 and y1==y3)or(x2==x4 and y2==y4):
  print("yes")
 elif (x1==x4 and y1==y4)or(x2==x3 and y2==y3):
  print("yes")
 else:
  if(y1==y2)and(y1==y3)and(y1==y4):
   a1=max(x1,x2);a2=min(x1,x2)
   b1=max(x3,x4);b2=min(x3,x4)
   if a1>=b2 and a2<=b1:
    print("yes")
   else:
    print("no")
  elif (x1==x2)and(x1==x3)and(x1==x4):
   a1=max(y1,y2);a2=min(y1,y2)
   b1=max(y3,y4);b2=min(y3,y4)
   if a1>=b2 and a2<=b1:
    print("yes")
   else:
    print("no")
  else:
   print("no")

# cook your dish here
t=int(input())
for _ in range(t):
 x1,y1,x2,y2=map(int,input().split())
 x3,y3,x4,y4=map(int,input().split())
 if (x1==x3 and y1==y3)or(x2==x4 and y2==y4):
  print("yes")
 elif (x1==x4 and y1==y4)or(x2==x3 and y2==y3):
  print("yes")
 else:
  if(y1==y2)and(y1==y3)and(y1==y4):
   a1=max(x1,x2);a2=min(x1,x2)
   b1=max(x3,x4);b2=min(x3,x4)
   if a1>=b2 and a2<=b1:
    print("yes")
   else:
    print("no")
  elif (x1==x2)and(x1==x3)and(x1==x4):
   a1=max(y1,y2);a2=min(y1,y2)
   b1=max(y3,y4);b2=min(y3,y4)
   if a1>=b2 and a2<=b1:
    print("yes")
   else:
    print("no")
  else:
   print("no")