Given an array of integer $a_1, a_2, \ldots, a_n$. In one operation you can make $a_i := a_i + 1$ if $i < n$ and $a_i \leq a_{i + 1}$, or $i = n$ and $a_i \leq a_1$.

You need to check whether the array $a_1, a_2, \ldots, a_n$ can become equal to the array $b_1, b_2, \ldots, b_n$ in some number of operations (possibly, zero). Two arrays $a$ and $b$ of length $n$ are called equal if $a_i = b_i$ for all integers $i$ from $1$ to $n$.


-----Input-----

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 4 \cdot 10^4$) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) – the length of the array.

The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^9$) – the elements of the array $a$.

The third line of each test case contains $n$ integers $b_1, \ldots, b_n$ ($1 \le b_i \le 10^9$) – the elements of the array $b$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, output "YES" if you can get the array $b$, otherwise output "NO".

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).


-----Examples-----

Input
5
3
1 2 5
1 2 5
2
2 2
1 3
4
3 4 1 2
6 4 2 5
3
2 4 1
4 5 3
5
1 2 3 4 5
6 5 6 7 6
Output
YES
NO
NO
NO
YES


-----Note-----

In the first test case, the array $a$ is already equal to the array $b$.

In the second test case, we can't get the array $b$, because to do this we need to decrease $a_1$.

In the fifth test case, we can apply operations in order to the elements with indices $4, 3, 3,2,2,2,1,1,1,1$, and then get the array $[5,5,5,5,5]$. After that, you can apply operations in order to elements with indices $5,4,4,3,1$ and already get an array $[6,5,6,7,6]$.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for i in range(n):
		if A[i] > B[i]:
			return 'NO'
		elif A[i] == B[i]:
			continue
		elif B[i] <= B[(i + 1) % n] + 1:
			continue
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(solve())


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def Solve():
	for t in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if a[-1] > b[-1] or (b[-1] - b[0] > 1 and a[-1] != b[-1]):
			print('NO')
		else:
			for i in range(n - 2, -1, -1):
				if not (b[i] - b[i + 1] <= 1 and a[i] < b[i] or a[i] == b[i]):
					print('NO')
					break
			else:
				print('YES')
Solve()


import sys
input = sys.stdin.readline

def int_num():
	return int(input())

def int_list():
	return list(map(int, input().split()))

def str_list():
	s = input()
	return list(s[:len(s) - 1])

def instr():
	return input().strip()

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

def solve():
	n = int_num()
	a = int_list()
	b = int_list()
	for i in range(n):
		if b[i] < a[i]:
			print('NO')
			return
		if b[i] > a[i]:
			next_idx = (i + 1) % n
			if b[i] > b[next_idx] + 1:
				print('NO')
				return
	print('YES')

def main():
	t = int_num()
	while t:
		solve()
		t -= 1
	return
main()


import sys
sys.setrecursionlimit(10 ** 6)
from collections import Counter, deque, defaultdict
ip = sys.stdin.readline
op = sys.stdout.write
t = int(ip())
res = []
for _ in range(t):
	n = int(ip())
	a = [int(x) for x in ip().split()]
	b = [int(x) for x in ip().split()]
	f = 0
	for i in range(n):
		if a[i] > b[i]:
			f = 1
			break
	for i in range(n):
		if b[i] > a[i] and b[i] > b[(i + 1) % n] + 1:
			f = 1
			break
	if f:
		res.append('NO')
	else:
		res.append('YES')
for val in res:
	op(val + '\n')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			print('NO')
			break
		elif i == n - 1:
			if a[i] != b[i] and b[0] + 1 < b[i]:
				print('NO')
				break
		elif i != n - 1:
			if a[i] != b[i] and b[i + 1] + 1 < b[i]:
				print('NO')
				break
	else:
		print('YES')


import sys
import math
from collections import Counter
from collections import defaultdict

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def solve(a, b):
	if a == b:
		return 'YES'
	for i in range(len(a)):
		if a[i] > b[i]:
			return 'NO'
	for i in range(len(b) - 1):
		if a[i] < b[i]:
			if b[i] - b[i + 1] > 1:
				return 'NO'
	if b[-1] - b[0] > 1:
		if b[-1] != a[-1]:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	n = get_ints()
	arr = get_ints()
	arr2 = get_ints()
	print(solve(arr, arr2))


import sys

def solve():
	inp = sys.stdin.readline
	n = int(inp())
	a = list(map(int, inp().split()))
	b = list(map(int, inp().split()))
	while True:
		ok = False
		z = True
		i = n - 1
		if a[i] <= a[0] and b[i] > a[i]:
			a[i] = min(a[0] + 1, b[i])
			ok = True
		for i in range(n - 2, -1, -1):
			if a[i] <= a[i + 1] and b[i] > a[i]:
				a[i] = min(a[i + 1] + 1, b[i])
				ok = True
			if a[i] != a[i + 1] + 1:
				z = False
		if not ok:
			break
		if z:
			w = b[0] - a[0]
			if b[0] < a[0]:
				print('NO')
				return
			for i in range(1, n):
				if b[i] < a[i]:
					print('NO')
					return
				w = min(w, b[i] - a[i])
			for i in range(n):
				a[i] += w
	if a == b:
		print('YES')
	else:
		print('NO')

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	if any([a[i] > b[i] for i in range(n)]):
		print('NO')
		continue
	minb = min(b)
	for i in range(n):
		a[i] = max(a[i], minb)
	minidx = 0
	for i in range(n):
		if b[i] == minb:
			minidx = i
			break
	verd = True
	for i in range(minidx, -1, -1):
		if a[i] == b[i]:
			continue
		if b[i] <= 1 + a[(i + 1) % n]:
			a[i] = b[i]
		else:
			verd = False
			break
	if not verd:
		print('NO')
		continue
	for i in range(n - 1, minidx, -1):
		if a[i] == b[i]:
			continue
		if b[i] <= 1 + a[(i + 1) % n]:
			a[i] = b[i]
		else:
			verd = False
			break
	if not verd:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	j = -1
	for i in range(n):
		if A[i] > B[i]:
			return 'NO'
		elif A[i] == B[i]:
			j = i
	(ma, mi) = (max(A), min(B))
	idx = min([i for i in range(n)], key=lambda x: B[x])
	k = max([i for i in range(n)], key=lambda x: A[x])
	if j > -1:
		idx = j
	elif ma > mi:
		prev = A[k]
		for i in range(1, n):
			j = (k - i) % n
			if j == idx:
				if B[j] <= prev + 1:
					A[j] = B[j]
					break
				else:
					return 'NO'
			else:
				A[j] = min(max(prev + 1, A[j]), B[j])
	else:
		A = [mi] * n
	prev = A[idx]
	for i in range(n):
		j = (idx - i) % n
		if A[j] == B[j]:
			prev = B[j]
		elif B[j] <= prev + 1:
			prev = B[j]
		else:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(solve())


import sys
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in sys.stdin.readline().split()]
	b = [int(x) for x in sys.stdin.readline().split()]
	bad = False
	for i in range(n):
		if a[i] > b[i] or (b[i] - b[(i + 1) % n] > 1 and b[i] != a[i]):
			bad = True
			break
	sys.stdout.write('NO\n') if bad else sys.stdout.write('YES\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	for x in range(n - 1, -1, -1):
		if a[x] != b[x] and (a[x] > b[x] or b[(x + 1) % n] + 1 < b[x]):
			flag = False
			break
	if flag:
		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()))
	flag = 'YES'
	for i in range(0, n):
		if a[i] > b[i]:
			flag = 'NO'
			break
		if b[i - 1] > b[i] + 1:
			if a[i - 1] != b[i - 1]:
				flag = 'NO'
				break
	if a[0] > b[0]:
		flag = 'NO'
	print(flag)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n - 1, -1, -1):
		if b[(i + 1) % n] >= b[i] - 1 and a[i] < b[i] or a[i] == b[i]:
			continue
		else:
			print('NO')
			return
	print('YES')
t = 1
t = int(input())
while t:
	solve()
	t -= 1


import sys
N = int(input())
for case in range(N):
	n = int(input())
	a_arr = list(map(int, sys.stdin.readline().split()))
	b_arr = list(map(int, sys.stdin.readline().split()))
	answer = 'YES'
	for i in range(n):
		if a_arr[i] > b_arr[i]:
			answer = 'NO'
			break
		elif a_arr[i] < b_arr[i]:
			next = i + 1
			if next == n:
				next = 0
			if b_arr[i] > b_arr[next] + 1:
				answer = 'NO'
				break
	print(answer)


def solve():
	x = int(input())
	for __ in range(x):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print('YES') if check(a, b, n) else print('NO')

def check(a, b, n):
	otc = False
	for i in range(n):
		if a[i] > b[i]:
			return False
		elif a[i] == b[i]:
			otc = True
			continue
		elif i < n - 1:
			if a[i + 1] >= a[i]:
				otc = True
			if b[i + 1] + 1 < b[i] or b[i + 1] + 1 < a[i]:
				return False
		else:
			if a[0] >= a[i]:
				otc = True
			if b[0] + 1 < b[i] or b[0] + 1 < a[i]:
				return False
	return otc
solve()


DEBUG = False
NO = 'NO'
YES = 'YES'

def solution(a, b):
	for (aa, bb) in zip(a, b):
		if aa > bb:
			return NO
	if a == b:
		return YES
	for i in range(len(a)):
		if b[(i + 1) % len(a)] < b[i] - 1 and b[i] != a[i]:
			return NO
	return YES

def main():
	if DEBUG:
		import os
		os.chdir(os.path.dirname(__file__))
		global input
		f = open('Sample.txt')
		input = lambda : f.readline().strip()
	T = int(input())
	for t in range(T):
		_ = input()
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print(solution(a, b))
main()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(-1, n - 1):
		if a[i] > b[i] or (b[i] > b[i + 1] + 1 and a[i] != b[i]):
			print('NO')
			break
	else:
		print('YES')
	t -= 1


def solve(t=int):
	return list(map(t, input().split()))

def ss():
	n = int(input())
	a = solve()
	b = solve()
	for i in range(0, n):
		if a[i] != b[i] and b[i] > b[(i + 1) % n] + 1 or a[i] > b[i]:
			print('NO')
			return
	print('YES')
t = int(input())
for x in range(0, t):
	ss()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = True
	d = True
	for i in range(n):
		if (a[i] > b[i] or b[i] > b[(i + 1) % n] + 1) and a[i] != b[i]:
			c = False
			break
	if c:
		print('YES')
	else:
		print('NO')


for t in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	for i in range(0, n):
		if b[i] < a[i]:
			flag = False
			break
		elif (a[i] != b[i]) & (b[i] > b[(i + 1) % n] + 1):
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


class T:

	def solve(self):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		flag = False
		for i in range(n):
			if a[i] > b[i]:
				return 'NO'
			if a[i] < b[i] and b[i] > b[(i + 1) % n] + 1:
				return 'NO'
		return 'YES'
for t in range(int(input())):
	obj = T()
	print(obj.solve())


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	out = False
	for x in range(n - 1):
		if l1[x] > l2[x]:
			out = True
			break
		if l1[x] != l2[x] and l2[x] - l2[x + 1] >= 2:
			out = True
			break
	if l1[-1] > l2[-1]:
		out = True
	if l1[-1] != l2[-1] and l2[-1] - l2[0] >= 2:
		out = True
	if not out:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	ans = 'YES'
	for i in range(n):
		if i != n - 1:
			if arr2[i] - arr2[i + 1] >= 2 and arr1[i] != arr2[i] or arr1[i] > arr2[i]:
				ans = 'NO'
				break
		else:
			if arr1[i] > arr2[i]:
				ans = 'NO'
				break
			if arr2[i] - arr2[0] >= 2 and arr1[i] != arr2[i] or arr1[i] > arr2[i]:
				ans = 'NO'
				break
	print(ans)
	t -= 1


import math as mt
from collections import defaultdict, deque
from posixpath import split
import sys
from bisect import bisect_right as b_r
from bisect import bisect_left as b_l
mod = 1000000007
INT_MAX = sys.maxsize - 1
INT_MIN = -sys.maxsize

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n - 1):
		if a[i] == b[i]:
			continue
		elif a[i] > b[i]:
			return 'NO'
		elif b[i] > b[i + 1] and b[i] - b[i + 1] > 1:
			return 'NO'
	if b[-1] - b[0] > 1 and b[-1] != a[-1] or a[-1] > b[-1]:
		return 'NO'
	else:
		return 'YES'
for _ in range(int(input())):
	print(solve())


def fun(a, b):
	for i in range(len(a)):
		if a[i] > b[i]:
			return 0
	for i in range(len(a)):
		if b[i] > b[(i + 1) % n] + 1 and b[i] > a[i]:
			return 0
	return 1
for _ in range(int(input())):
	n = int(input())
	f = input().split()
	s = input().split()
	f = list(map(int, f))
	s = list(map(int, s))
	if fun(f, s):
		print('YES')
	else:
		print('NO')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if b[(i + 1) % n] < b[i % n] and b[i % n] - b[(i + 1) % n] > 1 and (a[i % n] < b[i % n]) or a[i % n] > b[i % n]:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(solve())


def formal_statement(a, b):
	for (ai, bi) in zip(a, b):
		if ai > bi:
			return False
	for i in range(len(b)):
		if b[(len(b) + i) % len(b)] - b[(len(b) + i + 1) % len(b)] > 1 and a[i] != b[i]:
			return False
	return True
num_tests = int(input())
for _ in range(num_tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if formal_statement(a, b):
		print('YES')
	else:
		print('NO')


import collections

def decode(num):
	res = [0 for _ in range(31)]
	idx = 0
	while num > 0:
		res[idx] = num % 2
		idx += 1
		num >>= 1
	return res

def solve():
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	for i in range(len(a)):
		if a[i] > b[i]:
			print('NO')
			return
	b.append(b[0])
	for i in range(n):
		if b[i] > b[i + 1] + 1 and a[i] != b[i]:
			print('NO')
			return
	print('YES')
t = int(input().strip())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			print('NO')
			break
	else:
		for i in range(n):
			if a[i] == b[i]:
				continue
			elif b[i] > b[(i + 1) % n]:
				if b[i] - b[(i + 1) % n] > 1:
					print('NO')
					break
		else:
			print('YES')


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	for i in range(n):
		if a[i] > b[i]:
			print('NO')
			break
		if b[i] > a[i] and b[i] > b[(i + 1) % n] + 1:
			print('NO')
			break
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	flag = True
	for i in range(n):
		if arr[i] == brr[i]:
			continue
		elif arr[i] > brr[i]:
			flag = False
			break
		elif brr[i] > brr[(i + 1) % n] + 1:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	arr.append(arr[0])
	brr.append(brr[0])
	i = 0
	possible = True
	for i in range(n):
		if arr[i] == brr[i]:
			continue
		if brr[i] > brr[i + 1] + 1:
			possible = False
			break
		if arr[i] > brr[i]:
			possible = False
			break
	if not possible:
		print('NO')
	else:
		print('YES')


def solve(n, A, B):
	for i in range(0, n):
		inext = (i + 1) % n
		a = int(A[i])
		b = int(B[i])
		anext = int(A[inext])
		bnext = int(B[inext])
		if a > b:
			return 'NO'
		if a < b and b > bnext + 1:
			return 'NO'
	return 'YES'
t = int(input())
for i in range(0, t):
	n = int(input())
	a = input().split(' ')
	b = input().split(' ')
	print(solve(n, a, b))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = 0
	for k in range(n - 1):
		if a[k] < b[k]:
			if b[k] <= b[k + 1] + 1:
				pass
			else:
				f = 1
				break
		elif a[k] > b[k]:
			f = 1
			break
	if a[n - 1] < b[n - 1]:
		if b[n - 1] <= b[0] + 1:
			pass
		else:
			f = 1
	elif a[n - 1] > b[n - 1]:
		f = 1
	if f == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for iteration in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	answer = True
	for i in range(n):
		if a[i] > b[i]:
			answer = False
			break
		elif a[i] == b[i]:
			pass
		elif b[(i + 1) % n] >= b[i] - 1:
			pass
		else:
			answer = False
			break
	if answer is True:
		print('YES')
	else:
		print('NO')


from collections import *

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if b[i] < a[i]:
			print('NO')
			return
		if b[i] == a[i]:
			continue
		elif b[i] > b[(i + 1) % n] + 1:
			print('NO')
			return
	print('YES')
t = int(input())
for _ in range(t):
	solve()


R = lambda : map(int, input().split())
(t,) = R()
for _ in range(t):
	(n,) = R()
	a = list(R())
	b = list(R())
	q = False
	if a[-1] != b[-1]:
		if a[-1] <= b[-1]:
			if b[-1] - 1 <= b[0]:
				q = False
			else:
				q = True
		else:
			q = True
	if q:
		print('NO')
	else:
		i = n - 2
		jv = b[-1]
		while i >= 0:
			if a[i] == b[i]:
				jv = b[i]
				i -= 1
				continue
			if a[i] <= b[i]:
				if b[i] - 1 <= jv:
					jv = b[i]
				else:
					q = True
					break
			else:
				q = True
				break
			i -= 1
		if q:
			print('NO')
		else:
			print('YES')


r = int(input())
while r:
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	flag = True
	for i in range(n):
		if arr[i] == brr[i]:
			continue
		if arr[i] > brr[i]:
			print('NO')
			flag = False
			break
		if arr[i] < brr[i]:
			if i == n - 1:
				if brr[i] > brr[0] + 1:
					print('NO')
					flag = False
					break
			elif brr[i] > brr[i + 1] + 1:
				print('NO')
				flag = False
				break
	if flag:
		print('YES')
	r -= 1


t = int(input())
for k in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	bad = any([ai > bi or (ai < bi and bi - bi1 > 1) for (ai, bi, bi1) in zip(a, b, b[1:] + [b[0]])])
	if bad:
		print('NO')
	else:
		print('YES')


def Solution(a, b, n):
	for i in range(n):
		if a[i] > b[i]:
			return 'NO'
		elif a[i] < b[i]:
			if i < n - 1 and b[i] > b[i + 1] + 1:
				return 'NO'
			elif i == n - 1 and b[i] > b[0] + 1:
				return 'NO'
	return 'YES'
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(Solution(a, b, n))


t = int(input())
for j in range(t):
	n = int(input())
	A = [int(a) for a in input().split()]
	B = [int(b) for b in input().split()]
	A.append(A[0])
	B.append(B[0])
	ans = 'YES'
	for i in range(n):
		if A[i] > B[i]:
			ans = 'NO'
			break
		elif A[i] == B[i]:
			continue
		elif B[i + 1] + 1 < B[i]:
			ans = 'NO'
			break
	print(ans)


def fr(t=int):
	return list(map(t, input().split()))
T = int(input())
for t in range(1, T + 1):
	n = int(input())
	a = fr()
	b = fr()
	print('YES' if all([b[i] >= a[i] and (b[i] == a[i] or b[i] <= b[(i + 1) % n] + 1) for i in range(n)]) else 'NO')


def solve(n, a, b):
	for i in range(n):
		if a[i] == b[i]:
			continue
		j = (i + 1) % n
		if a[i] > b[i] or b[i] - b[j] > 1:
			return False
	return True
tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('YES' if solve(n, a, b) else 'NO')


from re import A

def solve(a, b):
	for (x, y) in zip(a, b):
		if x > y:
			return False
	n = len(a)
	a = a + a
	b = b + b
	for i in range(n):
		if a[i] == b[i]:
			continue
		if b[i] > b[i + 1] + 1:
			return False
	return True
t = int(input())
for _ in range(t):
	input()
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	if solve(a, b):
		print('YES')
	else:
		print('NO')


def solve(n, a, b):
	for i in range(len(a)):
		if a[i] > b[i]:
			print('NO')
			return
		if a[i] != b[i] and b[(i + 1) % n] + 1 < b[i]:
			print('NO')
			return
	print('YES')
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	solve(n, a, b)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(ii) for ii in input().split()]
	b = [int(ii) for ii in input().split()]
	a.append(a[0])
	b.append(b[0])
	if a == b:
		print('YES')
		continue
	stop = 0
	for i in range(n):
		if a[i] > b[i]:
			stop = 1
			break
		if b[i] - b[i + 1] > 1 and a[i] < b[i]:
			stop = 1
			break
	if stop == 1:
		print('NO')
	else:
		print('YES')


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('YES' if all([b[i] >= a[i] and (b[i] == a[i] or b[i] <= b[(i + 1) % n] + 1) for i in range(n)]) else 'NO')


def ans(arr1, arr2):
	k = len(arr1)
	for i in range(0, k):
		if arr1[i] > arr2[i]:
			return 'NO'
		if arr2[i] - 1 > arr2[(i + 1) % k]:
			if arr2[i] != arr1[i]:
				return 'NO'
	return 'YES'
test_cases = int(input())
while test_cases != 0:
	d = input()
	d2 = list(map(int, input().split()))
	d3 = list(map(int, input().split()))
	print(ans(d2, d3))
	test_cases -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	B.append(B[0])
	res = 'YES'
	for i in range(n):
		if A[i] == B[i]:
			continue
		if A[i] > B[i]:
			res = 'NO'
			break
		if B[i + 1] < B[i] - 1:
			res = 'NO'
			break
	print(res)


def get_prev_idx(n, i):
	if i - 1 < 0:
		return n - 1
	return i - 1

def solve(n, a, b):
	b_min = min(b)
	for i in range(n):
		if b_min == b[i]:
			idx = i
			break
	for _ in range(n):
		if b[idx] < a[idx]:
			return 'NO'
		prev = get_prev_idx(n, idx)
		if b[prev] - b[idx] <= 1:
			idx = prev
			continue
		if b[prev] == a[prev]:
			idx = prev
			continue
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	a = [int(e) for e in input().split()]
	b = [int(e) for e in input().split()]
	print(solve(n, a, b))


t = int(input())

def solve(n, a, b):
	for i in range(n):
		if b[i] < a[i]:
			return 'NO'
		if b[i] > a[i] and b[(i + 1) % n] < b[i] - 1:
			return 'NO'
	return 'YES'
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(solve(n, a, b))


def solve(a, b, n):
	for i in range(n):
		if a[i] > b[i]:
			return 'NO'
		if i < n - 1:
			if b[i] != a[i]:
				if b[i + 1] + 1 >= b[i]:
					pass
				else:
					return 'NO'
		elif b[i] != a[i]:
			if b[0] + 1 >= b[i]:
				pass
			else:
				return 'NO'
	return 'YES'
t = int(input())
for ii in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b, n))


t = int(input())
for k in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	succ = 1
	for i in range(n):
		if a[i] > b[i]:
			succ = 0
			break
		elif a[i] < b[i] and b[i % n] - b[(i + 1) % n] > 1:
			succ = 0
			break
	if succ == 1:
		print('YES')
	else:
		print('NO')


def f():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
		return
	f1 = 1
	for i in range(n):
		if a[i] > b[i]:
			f1 = 0
			break
	if f1 == 0:
		print('NO')
		return
	f = 0
	if a[n - 1] != b[n - 1]:
		f = 1
		a[n - 1] = b[n - 1]
	for i in range(n - 2, -1, -1):
		if a[i + 1] + 1 >= b[i] or a[i] == b[i]:
			a[i] = b[i]
		else:
			f1 = 0
			break
	if f1 == 0:
		print('NO')
		return
	if f == 0:
		print('YES')
	elif a[n - 1] - a[0] <= 1:
		print('YES')
	else:
		print('NO')
t = int(input())
while t:
	f()
	t -= 1


t = int(input())
for ta in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	if l == m:
		print('YES')
	else:
		fl1 = 0
		for i in range(n):
			if m[(i + 1) % n] <= m[i % n] - 2 and l[i % n] != m[i % n] or m[i % n] < l[i % n]:
				fl1 = 1
				print('NO')
				break
		if fl1 == 0:
			print('YES')


t = int(input())
for i in range(t):
	f = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] == b[i]:
			continue
		elif a[i] > b[i]:
			print('NO')
			f = 1
			break
		elif i == n - 1:
			if b[i] > b[0] + 1:
				print('NO')
				f = 1
				break
		elif b[i] > b[i + 1] + 1:
			print('NO')
			f = 1
			break
	if f == 0:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b += [b[0]]
	ans = True
	i = -1
	for i in range(n):
		if a[i] > b[i]:
			ans = False
			break
		if a[i] < b[i]:
			if b[i] - 1 > b[i + 1]:
				ans = False
				break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = tuple(map(int, input().split()))
	b = tuple(map(int, input().split()))
	print('YES' if all((a[i] <= b[i] and (b[i] == a[i] or b[i] <= b[(i + 1) % n] + 1) for i in range(n))) else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		(ai, aj) = (a[i], a[(i + 1) % n])
		(bi, bj) = (b[i], b[(i + 1) % n])
		if ai > bi or (ai < bi and bj < bi - 1):
			print('NO')
			break
	else:
		print('YES')


for caseno in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a += [a[0]]
	b += [b[0]]
	answer = True
	for i in range(n):
		if a[i] > b[i] or (a[i] < b[i] and b[i] > b[i + 1] + 1):
			answer = False
			break
	if answer:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n,) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	f = False
	for i in range(n):
		if b[(i + 1) % n] <= b[i] - 2 and a[i] != b[i] or a[i] > b[i]:
			f = True
			break
	if f:
		print('NO')
	else:
		print('YES')