Arya and Aryan live in a country called Nadaca. Nadaca consists of $N$ cities numbered $1$ through $N$, which are connected by some bidirectional roads. Each road has a positive (not necessarily integer) length. Arya lives in city $1$ and Aryan lives in city $N$.
Arya claims that for each city $v$, the shortest path from city $1$ to city $v$ has length $a_v$. Aryan does not disagree, but claims that for each city $v$, the shortest path from city $N$ to city $v$ has length $b_v$. You are the wisest person they know, so they asked you to tell them if it is possible for their claims to be true, i.e. if a road network which fully satisfies their claims exists. Help them!

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $a_1, a_2, \ldots, a_N$.
- The third line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$.

-----Output-----
For each test case, print a single line containing the string "Yes" if Arya's and Aryan's claims can be true or "No" otherwise.

-----Constraints-----
- $1 \le T \le 10^3$
- $2 \le N \le 10^6$
- $0 \le a_i, b_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Subtasks-----
Subtask #1 (50 points): the sum of $N$ over all test cases does not exceed $10^3$
Subtask #2 (50 points): original constraints

-----Example Input-----
2
3
0 1 1
1 1 0
3
0 1 5
5 1 0

-----Example Output-----
Yes
No

Difficulty: HARD
Tags: Constructive algorithms

Graph algorithms

Data structures

Ad-hoc
Skill types: Data structures

Starter code:

Solutions:
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if A[0] != 0 or B[N - 1] != 0 or A[N - 1] != B[0]:
		print('No')
		continue
	ans = 'Yes'
	for i in range(N):
		if i != 0 and A[i] == 0:
			ans = 'No'
			break
		if i != N - 1 and B[i] == 0:
			ans = 'No'
			break
		if A[i] + B[i] < B[0] or A[i] + B[0] < B[i] or B[i] + B[0] < A[i]:
			ans = 'No'
			break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(float, input().split()))
	b = list(map(float, input().split()))
	if a[0] != 0 or b[n - 1] != 0:
		print('No')
		continue
	if a[n - 1] != b[0]:
		print('No')
		continue
	flag = 0
	z = b[0]
	for j in range(0, n):
		x = a[j]
		y = b[j]
		if x == 0 and j != 0:
			flag = 1
			break
		if y == 0 and j != n - 1:
			flag = 1
			break
		if x + y < z or x + z < y or y + z < x:
			flag = 1
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr1 = list(map(int, input().strip().split()))
	arr2 = list(map(int, input().strip().split()))
	if arr1[0] == arr2[-1] == 0:
		if arr1[-1] == arr2[0]:
			if n > 2:
				if arr1[-1] != 0:
					k = 0
					for i in range(1, n - 1):
						if arr1[i] != 0 and arr2[i] != 0:
							if arr1[i] + arr2[i] < arr2[0]:
								k = 1
								break
							if arr1[i] + arr2[0] < arr2[i]:
								k = 1
								break
							if arr2[i] + arr2[0] < arr1[i]:
								k = 1
								break
						else:
							k = 1
							break
					if k == 0:
						print('Yes')
					else:
						print('No')
				else:
					print('No')
			elif arr1[-1] != 0:
				print('Yes')
			else:
				print('No')
		else:
			print('No')
	else:
		print('No')


def fun(a, b, c):
	if a + b < c or b + c < a or a + c < b:
		return False
	if a + b <= c or b + c <= a or a + c <= b:
		return 1
	return True
t = int(input())
for z in range(t):
	n = int(input())
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	(a, b, ck, ct) = (lis1[-1], lis2[0], 0, 0)
	if a != b or lis1[0] != 0 or lis2[-1] != 0 or (lis1.count(0) > 1) or (lis2.count(0) > 1):
		print('No')
	else:
		for i in range(n - 2):
			if fun(a, lis1[i + 1], lis2[i + 1]) == False:
				ck = 1
				break
			elif fun(a, lis1[i + 1], lis2[i + 1]) == 1:
				ct += 1
		if ck == 1:
			print('No')
		else:
			print('Yes')


for i in range(int(input())):
	n = int(input())
	a = list(map(float, input().split()))
	b = list(map(float, input().split()))
	if a[0] != 0 or b[-1] != 0 or a[-1] != b[0] or (a[0] != b[-1]) or (a[0] == b[0]) or (b[-1] == a[-1]):
		print('No')
	else:
		s = b[0]
		for i in range(1, n - 1):
			l = [s, a[i], b[i]]
			l.sort()
			if l[0] + l[1] < l[-1]:
				print('No')
				break
		else:
			print('Yes')


def possible(a, b):
	if a[0] != 0 or b[-1] != 0:
		return False
	if a[-1] != b[0]:
		return False
	if a[-1] == 0:
		return False
	for i in range(1, len(a) - 1):
		ai = a[i]
		bi = b[i]
		if ai == 0 or bi == 0:
			return False
		if a[-1] > ai + bi:
			return False
		if ai > bi + a[-1]:
			return False
		if bi > ai + a[-1]:
			return False
	return True
T = int(input())
for _ in range(T):
	N = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if possible(a, b):
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	f = 1
	if A[-1] != B[0] or A[0] != 0 or B[-1] != 0:
		f = 0
	for i in range(1, N - 1):
		if A[i] + B[i] < A[-1] or A[i] + A[-1] < B[i] or A[-1] + B[i] < A[i] or (A[i] == 0) or (B[i] == 0):
			f = 0
			break
	if f == 0:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	x = 0
	l1 = list(map(float, input().split()))
	l2 = list(map(float, input().split()))
	if l1[0] == 0 and l2[n - 1] == 0 and (l1[n - 1] == l2[0]):
		for j in range(1, n - 1):
			if l1[j] == 0 or l2[j] == 0:
				x = 1
				break
			if l2[0] > l1[j] + l2[j]:
				x = 1
				break
			if l1[j] > l2[j] + l2[0]:
				x = 1
				break
			if l2[j] > l1[j] + l2[0]:
				x = 1
				break
	else:
		x = 1
	if x == 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] != 0 or b[-1] != 0 or a[-1] != b[0]:
		print('No')
	else:
		ab = b[0]
		flag = 0
		for i in range(1, n - 1):
			if a[i] == 0 or b[i] == 0:
				print('No')
				flag = 1
				break
			elif a[i] + b[i] < ab:
				print('No')
				flag = 1
				break
			elif a[i] > ab + b[i] or b[i] > ab + a[i]:
				print('No')
				flag = 1
				break
		if flag == 0:
			print('Yes')


def formtri(x, y, z):
	if x + y >= z and y + z >= x and (z + x >= y):
		return True

def check(A, B):
	if A[-1] != B[0] or A[-1] <= 0:
		return 'No'
	if not A[0] == B[-1] == 0:
		return 'No'
	for i in range(1, len(A) - 1):
		if not (A[i] > 0 and B[i] > 0):
			return 'No'
	mindist = A[-1]
	for i in range(1, len(A) - 1):
		if not formtri(A[i], B[i], mindist):
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	n = int(input())
	adis = list(map(int, input().split()))
	bdis = list(map(int, input().split()))
	print(check(adis, bdis))


for _ in range(int(input())):
	N = int(input())
	a = tuple(map(int, input().split()))
	b = tuple(map(int, input().split()))
	possible = True
	if a[0] != 0 or b[-1] != 0 or a[-1] != b[0]:
		possible = False
	else:
		dist = b[0]
		for i in range(N):
			if a[i] + b[i] < dist:
				possible = False
			elif b[i] > a[i] + dist or a[i] > b[i] + dist:
				possible = False
			elif (a[i] == 0 or b[i] == 0) and a[i] + b[i] != dist:
				possible = False
			elif i != 0 and a[i] == 0 or (i != N - 1 and b[i] == 0):
				possible = False
	print(('No', 'Yes')[possible])


t = int(input())
for tt in range(t):
	n = int(input())
	a = [float(x) for x in input().split()]
	b = [float(x) for x in input().split()]
	flag = False
	if a[0] != 0 or b[n - 1] != 0:
		flag = True
	if a[n - 1] != b[0]:
		flag = True
	if b[0] == 0:
		flag = True
	for i in range(1, n - 1):
		if a[i] + b[i] < b[0]:
			flag = True
		if a[i] + b[0] < b[i] or b[i] + a[n - 1] < a[i]:
			flag = True
		if a[i] == 0:
			flag = True
	if flag:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(float, input().split()))
	l2 = list(map(float, input().split()))
	a = l2[0]
	if l1[0] != 0 or l2[-1] != 0 or l1[-1] != l2[0]:
		print('No')
	else:
		flag = 1
		for i in range(1, n - 1):
			if l1[i] == 0 or l2[i] == 0:
				print('No')
				flag = 0
				break
			if l1[i] + l2[i] < a or l1[i] + a < l2[i] or a + l2[i] < l1[i]:
				print('No')
				flag = 0
				break
		if flag != 0:
			print('Yes')


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		flag = True
		if a[0] != 0 or b[n - 1] != 0 or a[n - 1] != b[0] or (a.count(0) > 1) or (b.count(0) > 1):
			flag = 0
		else:
			for i in range(1, n - 1):
				if a[i] + a[n - 1] < b[i] or a[i] + b[i] < a[n - 1] or b[i] + a[n - 1] < a[i]:
					flag = 0
				if not flag:
					break
		if flag == 1:
			print('Yes')
		else:
			print('No')
main()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	if a[0] != 0 or b[n - 1] != 0 or b[0] == 0 or (a[n - 1] == 0):
		flag = 1
	if a[n - 1] != b[0]:
		flag = 1
	for i in range(1, n - 1):
		if a[i] + b[i] < a[n - 1]:
			flag = 1
		else:
			if a[i] > a[n - 1] + b[i]:
				flag = 1
			if b[i] > b[0] + a[i]:
				flag = 1
	if flag == 1:
		print('No')
	else:
		print('Yes')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	ans = 'Yes'
	a_1 = A[0]
	a_n = A[n - 1]
	b_1 = B[0]
	b_n = B[n - 1]
	if a_1 != 0 or b_n != 0 or a_n != b_1:
		ans = 'No'
	else:
		for i in range(1, n - 1):
			if A[i] == 0 or B[i] == 0:
				ans = 'No'
				break
			elif b_1 + A[i] < B[i]:
				ans = 'No'
				break
			elif A[i] + B[i] < b_1:
				ans = 'No'
				break
			elif B[i] + b_1 < A[i]:
				ans = 'No'
				break
			else:
				pass
	print(ans)


for _ in range(int(input())):
	N = int(input())
	a = list(map(int, str.split(input())))
	b = list(map(int, str.split(input())))
	r = 'Yes'
	if a[-1] != b[0] or a[0] != 0 or b[-1] != 0:
		print('No')
		continue
	for i in range(N):
		if a[i] + b[i] < a[-1] or a[-1] + b[i] < a[i] or a[-1] + a[i] < b[i] or (i > 0 and a[i] == 0) or (i < N - 1 and b[i] == 0):
			r = 'No'
			break
	print(r)


def calculate_min_path(A, B):
	flag = 1
	if A[0] != 0 or B[n - 1] != 0:
		print('No')
		return
	if A[n - 1] != B[0]:
		print('No')
		return
	for i in range(1, n - 1):
		a = A[i]
		b = A[n - 1]
		c = B[i]
		if a > 0 and b > 0 and (c > 0):
			if a + b < c or a + c < b or b + c < a:
				flag = 0
				break
		else:
			flag = 0
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	calculate_min_path(A, B)


t = int(input())
for m in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	flag = 0
	if l1[0] != 0 or l1[-1] == 0 or l2[0] == 0 or (l2[-1] != 0) or (l1[-1] != l2[0]):
		flag = 1
	if flag != 1:
		for i in range(1, n - 1):
			if l1[i] + l2[i] < l1[-1]:
				flag = 1
				break
			if l1[-1] + l2[i] < l1[i]:
				flag = 1
				break
			if l1[-1] + l1[i] < l2[i]:
				flag = 1
				break
	if flag == 0:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	x = B[0]
	y = A[n - 1]
	r = 0
	if x != y or A[0] != 0 or B[n - 1] != 0:
		r = 1
	j = 1
	while r == 0 and j < n - 1:
		if A[j] + B[j] < x or abs(A[j] - B[j]) > x or A[j] <= 0 or (B[j] <= 0):
			r = 1
			break
		j += 1
	if r == 1:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = [0] + list(map(float, input().split()))
	b = [0] + list(map(float, input().split()))
	c = [0] + [0 for i in range(n)]
	ans = a[1] + b[1]
	flag = 0
	of = a[n]
	zz = 0
	if a[n] == b[1] and a.count(0) == 2 and (b.count(0) == 2):
		for i in range(2, n + 1):
			if a[i] + b[i] >= of and of + b[i] >= a[i] and (of + a[i] >= b[i]):
				zz = 1
			else:
				print('No')
				flag = 1
				break
	else:
		print('No')
		flag = 1
	if flag == 0:
		print('Yes')


for _ in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ab = A[-1]
	t = True
	if A[0] != 0 or B[-1] != 0 or A[-1] != B[0] or (A[0] != B[-1]):
		print('No')
		continue
	for i in range(len(A)):
		if 1 <= i <= N - 2 and (A[i] == 0 or B[i] == 0):
			t = False
			break
		if A[i] + B[i] < ab:
			t = False
			break
	if not t:
		print('No')
		continue
	for i in range(len(A)):
		if A[i] > ab + B[i]:
			t = False
			break
	if not t:
		print('No')
		continue
	for i in range(len(B)):
		if B[i] > ab + A[i]:
			t = False
			break
	if t:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 1
	if a[0] != 0 or b[n - 1] != 0:
		ans = 0
	elif a[n - 1] != b[0]:
		ans = 0
	else:
		minimum = a[n - 1]
		for i in range(1, n - 1):
			if a[i] + b[i] < minimum or a[i] > b[i] + minimum or b[i] > a[i] + minimum or (a[i] == 0) or (b[i] == 0):
				ans = 0
				break
	if ans:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]

	def check(A, B):
		c = 0
		if A[0] == B[n - 1] == 0:
			if A[n - 1] == B[0]:
				if n > 2:
					for i in range(1, n - 1):
						if A[i] + B[i] >= B[0]:
							if A[i] != 0 or B[i] != 0:
								if B[0] + A[i] >= B[i]:
									if B[0] + B[i] >= A[i]:
										c = c + 1
						else:
							break
					if c == n - 2:
						return 'Yes'
					else:
						return 'No'
				else:
					return 'Yes'
			else:
				return 'No'
		else:
			return 'No'
	print(check(A, B))


t = int(input())
for _ in range(t):
	n = int(input())
	claim1 = [int(x) for x in input().split()]
	claim2 = [int(x) for x in input().split()]
	count = 0
	if claim1[0] == claim2[n - 1] == 0:
		if claim1[n - 1] == claim2[0]:
			if n > 2:
				for i in range(1, n - 1):
					if claim1[i] + claim2[i] >= claim2[0]:
						if claim1[i] != 0 and claim2 != 0:
							if claim1[i] + claim2[0] >= claim2[i] and claim2[i] + claim2[0] >= claim1[i]:
								count += 1
					else:
						break
				if count == n - 2:
					print('Yes')
				else:
					print('No')
			else:
				print('Yes')
		else:
			print('No')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	fl = 1
	if a[0] != 0 or b[n - 1] != 0 or a[n - 1] != b[0]:
		fl = 0
	s = b[0]
	if fl:
		for i in range(n):
			if i != 0 and i != n - 1:
				if a[i] == 0 or b[i] == 0:
					fl = 0
					break
			if a[i] + b[i] < s:
				fl = 0
				break
			if s + b[i] < a[i]:
				fl = 0
				break
			if s + a[i] < b[i]:
				fl = 0
				break
	if fl:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mindis = b[0]
	if b[0] == a[-1] and a[0] == 0 and (b[-1] == 0) and (b[0] != 0):
		flag = True
		for i in range(1, n - 1):
			if a[i] + mindis < b[i] or b[i] + mindis < a[i] or a[i] + b[i] < mindis:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


def istriangle(a, b, c):
	if a <= 0 or b <= 0 or c <= 0:
		return False
	if a + b < c or a + c < b or b + c < a:
		return False
	else:
		return True

def valid(a, b, n):
	if a[0] != 0 or b[-1] != 0 or a[-1] != b[0]:
		return False
	for i in range(1, n - 1):
		if not istriangle(a[-1], a[i], b[i]):
			return False
	return True
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if valid(a, b, n):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = d = 0
	for i in range(n):
		if a[i] == 0:
			c += 1
		if b[i] == 0:
			d += 1
	flag = 0
	if a[0] != 0 or b[-1] != 0 or a[-1] != b[0] or (a[-1] <= 0) or (c >= 2) or (d >= 2):
		print('No')
	else:
		for i in range(1, n - 1):
			x = a[i]
			y = b[i]
			if x + y >= a[-1] and x + a[-1] >= y and (y + a[-1] >= x):
				pass
			else:
				flag = 1
				break
		if flag == 1:
			print('No')
		else:
			print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = list(map(int, input().split()))
	if aa[0] != 0 or bb[-1] != 0:
		print('No')
		continue
	if aa[-1] != bb[0]:
		print('No')
		continue
	if 0 in aa[1:] or 0 in bb[:n - 1]:
		print('No')
		continue
	ma = aa[-1]
	ans = 'Yes'
	for i in range(1, n - 1):
		if aa[i] + bb[i] < ma:
			ans = 'No'
		if aa[-1] + bb[i] < aa[i]:
			ans = 'No'
		if aa[i] + bb[0] < bb[i]:
			ans = 'No'
	print(ans)


T = int(input())
if 1 <= T <= 1000:
	k = 0
	for i in range(T):
		N = int(input())
		k = k + N
		if 2 <= N <= 1000000 and 2 <= k <= 1000000 and (k <= 1000000 - 2 * (T - i - 1)):
			a = list(map(int, input().split()))
			b = list(map(int, input().split()))
			if len(a) == N and len(b) == N and (0 <= m <= 1000000000 for m in a) and (0 <= m <= 1000000000 for m in b):
				count = 0
				for j in range(N):
					if a[j] + b[j] < a[N - 1] or a[j] + a[N - 1] < b[j] or b[j] + a[N - 1] < a[j] or (j > 0 and a[j] == 0) or (j < N - 1 and b[j] == 0):
						count = 1
						break
				if count == 0 and a[0] == b[N - 1] == 0 and (a[N - 1] == b[0]):
					print('Yes')
				else:
					print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = [float(x) for x in input().split()]
	b = [float(x) for x in input().split()]
	count = 1
	if b[0] != a[n - 1] or a[0] != 0 or b[n - 1] != 0 or (a.count(0 / 1) != 1) or (b.count(0 / 1) != 1):
		count = -1
	else:
		j = 1
		while j < n - 1:
			x = a[j]
			y = b[j]
			z = b[0]
			if x + y < z or y + z < x or z + x < y:
				count = -1
			if count == -1:
				break
			j += 1
	if count == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = [float(i) for i in input().split(' ')]
	b = [float(i) for i in input().split(' ')]
	flag = True
	if a[0] != b[-1] or a[-1] != b[0] or a[0] != 0 or (b[-1] != 0) or (a[-1] == 0):
		flag = False
	if flag:
		for i in range(len(a)):
			if a[i] + b[i] < b[0]:
				flag = False
				break
			if a[i] > a[-1] + b[i]:
				flag = False
				break
			if b[i] > b[0] + a[i]:
				flag = False
				break
	if flag:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if arr[0] != 0 or brr[n - 1] != 0 or arr[n - 1] != brr[0]:
		print('No')
	else:
		count = 0
		for i in range(1, n - 1):
			if arr[i] == 0 or brr[i] == 0:
				count = 1
				break
			if arr[i] + brr[i] < arr[n - 1]:
				count = 1
				break
			if arr[n - 1] + brr[i] < arr[i]:
				count = 1
				break
			if brr[0] + arr[i] < brr[i]:
				count = 1
				break
		if count == 1:
			print('No')
		else:
			print('Yes')
	t = t - 1


from sys import stdin, stdout
from collections import defaultdict, Counter
import math
I = stdin.readline
P = stdout.write
t = int(I())
for _ in range(t):
	n = int(I())
	a = [int(x) for x in I().split()]
	b = [int(x) for x in I().split()]
	x = a[-1]
	y = b[0]
	if x != y or b[-1] != 0 or a[0] != 0:
		print('No')
	else:
		flag = 0
		for i in range(1, n - 1):
			if a[i] + b[i] < x or abs(a[i] - b[i]) > x or a[i] <= 0 or (b[i] <= 0):
				flag = 1
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	flag = 1
	if a[0] != 0 or b[n - 1] != 0:
		flag = 0
	if a[n - 1] != b[0]:
		flag = 0
	for i in range(1, n - 1):
		if a[i] == 0 or b[i] == 0:
			flag = 0
		if a[i] + b[i] < b[0]:
			flag = 0
		if b[0] + a[i] < b[i]:
			flag = 0
		if b[i] + b[0] < a[i]:
			flag = 0
	if flag == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = 0
	if a[0] != 0:
		f = 1
	if b[-1] != 0:
		f = 1
	if b[0] != a[-1]:
		f = 1
	if f == 0:
		for j in range(1, n - 1):
			if a[j] == 0 or b[j] == 0:
				f = 1
				break
			if b[0] > a[j] + b[j] or a[j] > b[j] + b[0] or b[j] > a[j] + b[0]:
				f = 1
				break
	if f == 1:
		print('No')
	else:
		print('Yes')


try:
	t = int(input())
	for case in range(t):
		n = int(input())
		a = [int(i) for i in input().split()]
		b = [int(i) for i in input().split()]
		yes = True
		if a[0] != 0 or b[n - 1] != 0:
			print('No')
			yes = False
		elif a[n - 1] != b[0]:
			print('No')
			yes = False
		else:
			for edge in range(1, n - 1):
				if a[edge] == 0 or b[edge] == 0:
					print('No')
					yes = False
					break
				elif a[edge] + b[edge] < b[0]:
					print('No')
					yes = False
					break
				elif a[edge] + b[0] < b[edge]:
					print('No')
					yes = False
					break
				elif a[n - 1] + b[edge] < a[edge]:
					print('No')
					yes = False
					break
		if yes:
			print('Yes')
except EOFError:
	pass


def triangle(a, b, c):
	if a + b < c:
		return -1
	if b + c < a:
		return -1
	if a + c < b:
		return -1
	return 1

def funq(a, b):
	if a[0] != 0:
		return 'No'
	if b[len(b) - 1] != 0:
		return 'No'
	if a[len(a) - 1] != b[0]:
		return 'No'
	for i in range(1, len(b) - 1, +1):
		if a[i] == 0 or b[i] == 0:
			return 'No'
		if triangle(a[i], b[i], b[0]) == -1:
			return 'No'
	return 'Yes'
t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	print(funq(l1, l2))


t = int(input())
for _ in range(t):
	n = int(input())
	a1 = input()
	b1 = input()
	a = list(map(int, a1.split()))
	b = list(map(int, b1.split()))
	c1 = a.count(0)
	c2 = b.count(0)
	flag = False
	if c1 == 1 and c2 == 1 and (a[n - 1] == b[0]):
		k = a[n - 1]
		for i in range(1, n - 1):
			m = a[i]
			n = b[i]
			if k <= m + n and m <= k + n and (n <= k + m):
				flag = False
			else:
				flag = True
				break
		if flag:
			print('No')
		else:
			print('Yes')
	else:
		print('No')


def check_claim(A, B, n):
	if A[0] or B[-1]:
		return False
	if A[-1] != B[0]:
		return False
	if n == 2:
		return True
	for i in range(1, n - 1):
		(l1, l2, l3) = (B[0], A[i], B[i])
		if l1 > l2 + l3 or l2 > l1 + l3 or l3 > l1 + l2 or (l1 * l2 * l3 == 0):
			return False
	return True
t = int(input())
for test in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	if check_claim(A, B, n):
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	n = int(input())
	la = list(map(float, input().split()))
	lb = list(map(float, input().split()))
	lol = 0
	if la[n - 1] != lb[0] or la[0] != 0 or lb[n - 1] != 0 or (la[n - 1] == 0) or (lb[0] == 0):
		lol = 1
	else:
		for i in range(n):
			a = la[i]
			b = lb[i]
			c = la[n - 1]
			if a + b < c or a + c < b or b + c < a:
				lol = 1
				break
	if lol == 0:
		print('Yes')
	else:
		print('No')
	t -= 1


t = int(input())
for j in range(t):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	if ar1[n - 1] != ar2[0]:
		print('No')
		continue
	if ar1[0] != 0 or ar2[n - 1] != 0:
		print('No')
		continue
	alert = 0
	for i in range(1, n):
		if ar1[i] == 0:
			print('No')
			alert = 1
			break
	if alert == 1:
		continue
	for i in range(n - 1):
		if ar2[i] == 0:
			print('No')
			alert = 1
			break
	if alert == 1:
		continue
	mini1 = ar2[len(ar2) - 1]
	mini2 = ar1[len(ar1) - 1]
	for i in range(len(ar2)):
		if ar1[i] + ar2[i] < mini1 or ar1[i] + ar2[i] < mini2:
			print('No')
			alert = 1
			break
	if alert == 1:
		continue
	for i in range(1, len(ar1)):
		if ar1[i] + ar2[0] < ar2[i]:
			print('No')
			alert = 1
			break
	if alert == 1:
		continue
	for i in range(1, len(ar1)):
		if ar2[i] + ar1[n - 1] < ar1[i]:
			print('No')
			alert = 1
			break
	if alert == 1:
		continue
	print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(float, input().split()))
	B = list(map(float, input().split()))
	last1 = A.count(0)
	last2 = B.count(0)
	a = b = c = d = 0
	if A[n - 1] == B[0] and last1 == last2 == 1:
		b = A[n - 1]
		for i in range(1, n - 1):
			a = A[i]
			c = B[i]
			if b <= a + c and c <= b + a and (a <= b + c):
				d = 0
			else:
				d = 1
				break
		if d == 1:
			print('No')
		else:
			print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	if a[0] != 0 or b[n - 1] != 0 or a[n - 1] != b[0]:
		print('No')
		continue
	else:
		var = 0
		for x in range(1, n):
			if a[x] == 0:
				var = 1
				break
		for y in range(n - 1):
			if b[y] == 0:
				var = 1
				break
		dist = b[0]
		for x in range(1, n - 1):
			if a[x] + b[x] < dist or a[x] + dist < b[x] or b[x] + dist < a[x]:
				var = 1
				break
			elif a[x] - b[x] > dist or a[x] - dist > b[x] or b[x] - dist > a[x]:
				var = 1
				break
		if var == 0:
			print('Yes')
		else:
			print('No')


T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(float, input().split()))
	B = list(map(float, input().split()))
	if A[0] != 0 or B[-1] != 0 or A[-1] != B[0] or (B[0] == 0) or (A[-1] == 0):
		print('No')
	else:
		ok = 1
		R = A[0] + B[0]
		for i in range(1, N - 1):
			if A[i] + B[i] < R or A[i] > A[-1] + B[i] or B[i] > B[0] + A[i]:
				ok = 0
				print('No')
				break
		if ok:
			print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] != 0 or b[n - 1] != 0:
		print('No')
		continue
	if a[n - 1] != b[0]:
		print('No')
		continue
	f = 0
	for k in range(1, n - 1):
		if a[k] + b[k] < a[n - 1] or a[n - 1] + b[k] < a[k] or a[n - 1] + a[k] < b[k] or (a[k] == 0) or (b[k] == 0):
			print('No')
			f = 1
			break
	if f == 0:
		print('Yes')


def calculate_min_path(A, B):
	if A[0] != 0 or B[n - 1] != 0:
		return False
	if A[n - 1] != B[0]:
		return False
	for i in range(1, n - 1):
		(a, b, c) = (A[i], A[n - 1], B[i])
		if a + b < c or a + c < b or b + c < a or (a * b * c == 0):
			return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if calculate_min_path(A, B):
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] != b[len(b) - 1] or a[len(a) - 1] != b[0] or a[0] != 0 or (b[len(b) - 1] != 0) or (a.count(0) > 1) or (b.count(0) > 1):
		print('No')
	else:
		hmm = 0
		dab = a[len(a) - 1]
		for i in range(1, n - 1):
			if a[i] + b[i] < dab or a[i] + dab < b[i] or b[i] + dab < a[i]:
				hmm = 1
		if hmm == 0:
			print('Yes')
		else:
			print('No')


def check(n, a, b):
	for i in range(1, n):
		if a[i] == 0:
			return False
	for i in range(n - 1):
		if b[i] == 0:
			return False
	if a[-1] != b[0] or a[0] != 0 or b[-1] != 0:
		return False
	else:
		d = b[0]
		for i in range(1, n - 1):
			if d > a[i] + b[i]:
				return False
		for i in range(1, n - 1):
			if a[i] > d + b[i]:
				return False
			if b[i] > d + a[i]:
				return False
	return True
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if check(n, a, b):
		print('Yes')
	else:
		print('No')


t = int(input())
for ct in range(t):
	n = int(input())
	a = list(map(float, input().split()))
	b = list(map(float, input().split()))
	d = min((a[i] + b[i] for i in range(n)))
	if d == 0:
		print('No')
		continue
	is_valid = not a[0] and (not b[-1]) and (b[0] == a[-1]) and (b[0] == d)
	if is_valid:
		for (i, va) in enumerate(a):
			if b[i] > a[i] + d or a[i] > b[i] + d:
				is_valid = False
				break
	if is_valid:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] != 0 or b[n - 1] != 0 or a[n - 1] != b[0]:
		print('No')
	else:
		f = 1
		l = n - 1
		for i in range(1, n - 1):
			if a[i] == 0 or b[i] == 0 or a[i] + b[i] < a[l] or (a[l] + b[i] < a[i]) or (b[0] + a[i] < b[i]):
				print('No')
				f = 0
				break
		if f:
			print('Yes')


def ip():
	return int(input())

def ipp():
	return map(int, input().split())

def sar():
	return list(ipp())

def pars(a):
	print(' '.join(list(map(str, a))))
	print('\r')

def parl(a):
	print('\r'.join(list(map(str, a))))
	print('\r')
T = 1
T = int(input().strip())
for _ in range(T):
	n = ip()
	a = sar()
	b = sar()
	f = 0
	if a[0] != 0 or b[n - 1] != 0 or b[0] != a[-1]:
		print('No')
		continue
	gg = 0
	for i in range(n):
		if a[i] == 0 and i != 0:
			gg = 1
			break
		elif b[i] == 0 and i != n - 1:
			gg = 1
			break
	if gg == 1:
		print('No')
		continue
	for i in range(n):
		if b[0] > a[i] + b[i] or a[i] > b[i] + b[0] or b[i] > a[i] + b[0]:
			print('No')
			f = 1
			break
	if f == 0:
		print('Yes')


from collections import Counter
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = True
	if a[0] != 0 or b[n - 1] != 0:
		print('No')
	elif a[n - 1] != b[0]:
		print('No')
	else:
		for j in range(n):
			if j != 0 and j != n - 1:
				if a[j] + b[j] < a[n - 1] or a[j] > a[n - 1] + b[j] or b[j] > b[0] + a[j] or (a[j] == 0) or (b[j] == 0):
					print('No')
					c = False
					break
		if c == True:
			print('Yes')


def verify_dist(list_a, list_b, n):
	if list_a[0] != 0:
		return False
	if list_b[n - 1] != 0:
		return False
	if list_a[n - 1] != list_b[0]:
		return False
	else:
		short_dist = list_b[0]
		if not short_dist:
			return False
	for i in range(1, n - 1):
		if not list_a[i] or not list_b[i]:
			return False
		if list_a[i] + list_b[i] < short_dist:
			return False
		if list_a[i] + short_dist < list_b[i]:
			return False
		if list_b[i] + short_dist < list_a[i]:
			return False
	return True
t = int(input())
for t_i in range(t):
	n = int(input())
	list_a = [float(i) for i in input().split()]
	list_b = [float(i) for i in input().split()]
	if verify_dist(list_a, list_b, n):
		print('Yes')
	else:
		print('No')