You are in the future. It's the time of autonomous cars. Switching lanes is a pretty difficult task for autonomous cars, and you have the logs from an experiment you had run with two cars. You want to verify whether the logs are corrupted, or could be valid.
In that experiment, you had a highway consisting of two lanes. These were represented by 2 rows of an infinite grid. The cell (1, 1) is the top left cell which is the starting point of the first lane. Cell (2, 1) is the bottom left cell of the grid which is the starting point of the second lane.
There are two cars, 1 and 2 that start from the cell (1, 1) and (2, 1). 
At each instant, a car has the following choices.
- Stay at the current position.
- Move one cell to the right.
- Switch Lanes. When a car switches its lane, it stays in the same column. That is, from (1, i) it could go to (2, i), or from (2, i) it could go to (1, i). But both both cars shouldn't end up at the same cell at any point. Note that there could have been a car which had moved at the very instant that you move into it.
Consider one such scenario of driving cars.
Time $t = 0$
1.....
2.....

Time $t = 1$. Car 2 advances one cell right. Car 1 stays at the same place.
1.....
.2....

Time $t = 2$. Car 2 stays at its place. Car 1 switches the lane.
......
12....

Time $t = 3$. Car 2 moves one cell to the right.  Car 1 also moves one cell to the right.
......
.12...

Time $t = 4$. Both the cars stay in the same place.
......
.12...

You are given positions of the car at $n$ instants. Your task is to check whether this situation is feasible or not.

-----Input-----
- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows.
- The first line of each test case contains an integer $n$ denoting the number of instants where the positions of the cars were recorded.
- Each of next $n$ lines contains 5 space separated integers denoting $t_i, x_i, y_i, X_i, Y_i$ denoting time, $x$ and $y$ coordinate of the first car, and that of second car.

-----Output-----
For each test case, output either yes or no according to the answer to the problem.

-----Constraints-----
- $1 \le T \le 10^5$
- $1 \le n \leq 10^5$
- $1 \le t_i, y_i, X_i, Y_i \leq 10^9$
- $1 \leq x_i \leq 2$
- $t_i < t_{i+1}$
- Sum of $n$ over all the test cases doesn't exceed $10^6$

-----Example Input-----
2
3
1 1 1 2 2
2 2 1 2 2
4 2 2 2 3
1
1 1 3 2 2

-----Example Output-----
yes
no

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
def check(px, x):
	if px[1] == x[1]:
		return x[2] - px[2] <= x[0] - px[0] and x[2] >= px[2]
	else:
		return x[2] - px[2] + 1 <= x[0] - px[0] and x[2] >= px[2]

def checkdouble(px, x):
	if px[3] == x[3]:
		return x[4] - px[4] <= x[0] - px[0] and x[4] >= px[4]
	else:
		return x[4] - px[4] + 1 <= x[0] - px[0] and x[4] >= px[4]
for _ in range(int(input())):
	px = [0, 1, 1, 2, 1]
	g = True
	for _ in range(int(input())):
		x = list(map(int, input().split()))
		if x[1] == x[3] and x[2] == x[4]:
			g = False
		if not g:
			continue
		g = check(px, x)
		if g:
			g = checkdouble(px, x)
		px = x
	if not g:
		print('no')
	else:
		print('yes')


def check1(t, x, y, px, py):
	if x == px:
		return y - py <= t and py <= y
	return y - py + 1 <= t and py <= y

def check(px, x):
	t = x[0] - px[0]
	return check1(t, x[1], x[2], px[1], px[2]) and check1(t, x[3], x[4], px[3], px[4])
for _ in range(int(input())):
	px = [0, 1, 1, 2, 1]
	g = True
	for _ in range(int(input())):
		x = list(map(int, input().split()))
		if x[1] == x[3] and x[2] == x[4]:
			g = False
		if g:
			g = check(px, x)
		px = x
	if g:
		print('yes')
	else:
		print('no')


def time(x1, y1, x2, y2):
	if x1 == x2:
		return y2 - y1
	return y2 - y1 + 1
ans = ['no', 'yes']
for _ in range(int(input())):
	(t, fx, fy, sx, sy, f) = (0, 1, 1, 2, 1, 1)
	for _ in range(int(input())):
		a = [int(x) for x in input().split()]
		if f:
			if a[1] == a[3] and a[2] == a[4]:
				f = 0
				continue
			if fy > a[2] or sy > a[4]:
				f = 0
				continue
			t1 = time(fx, fy, a[1], a[2])
			t2 = time(sx, sy, a[3], a[4])
			_t = a[0] - t
			if t1 > _t or t2 > _t:
				f = 0
		(t, fx, fy, sx, sy) = a
	print(ans[f])