You're given two arrays $a[1 \dots n]$ and $b[1 \dots n]$, both of the same length $n$.

In order to perform a push operation, you have to choose three integers $l, r, k$ satisfying $1 \le l \le r \le n$ and $k > 0$. Then, you will add $k$ to elements $a_l, a_{l+1}, \ldots, a_r$.

For example, if $a = [3, 7, 1, 4, 1, 2]$ and you choose $(l = 3, r = 5, k = 2)$, the array $a$ will become $[3, 7, \underline{3, 6, 3}, 2]$.

You can do this operation at most once. Can you make array $a$ equal to array $b$?

(We consider that $a = b$ if and only if, for every $1 \le i \le n$, $a_i = b_i$)


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 20$) — the number of test cases in the input.

The first line of each test case contains a single integer $n$ ($1 \le n \le 100\ 000$) — the number of elements in each array.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$).

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$).

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$.


-----Output-----

For each test case, output one line containing "YES" if it's possible to make arrays $a$ and $b$ equal by performing at most once the described operation or "NO" if it's impossible.

You can print each letter in any case (upper or lower).


-----Example-----
Input
4
6
3 7 1 4 1 2
3 7 3 6 3 2
5
1 1 1 1 1
1 2 1 3 1
2
42 42
42 42
1
7
6

Output
YES
NO
YES
NO



-----Note-----

The first test case is described in the statement: we can perform a push operation with parameters $(l=3, r=5, k=2)$ to make $a$ equal to $b$.

In the second test case, we would need at least two operations to make $a$ equal to $b$.

In the third test case, arrays $a$ and $b$ are already equal.

In the fourth test case, it's impossible to make $a$ equal to $b$, because the integer $k$ has to be positive.

Difficulty: EASY

Solutions:
def f(a, b, n):
	r = 0
	j = 0
	sub = 0
	flag2 = False
	for k in range(n):
		if a[k] != b[k]:
			r = k
			sub = a[k] - b[k]
			flag2 = True
			break
	if sub > 0:
		return False
	flag = False
	if flag2:
		for k in range(r, n):
			if a[k] - b[k] != sub and a[k] != b[k]:
				return False
			if a[k] == b[k]:
				flag = not flag
			if a[k] - b[k] == sub and flag:
				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 f(a, b, n):
		print('YES')
	else:
		print('NO')


def a_to_b(a, b):
	n = len(a)
	if a == b:
		return 'YES'
	for i in range(n):
		if a[i] != b[i]:
			q = i
			dq = b[i] - a[i]
			break
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			w = i
			dw = b[i] - a[i]
			break
	if dq != dw:
		return 'NO'
	if dq <= 0:
		return 'NO'
	for i in range(q, w + 1):
		a[i] = a[i] + dq
	if a == b:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(a_to_b(a, b))


for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = []
	for i in range(n):
		d.append(b[i] - a[i])
	s = set(d)
	if len(s) == 1:
		if d[0] < 0:
			print('NO')
			continue
		print('YES')
		continue
	if len(s) > 2:
		print('NO')
		continue
	if 0 not in s:
		print('NO')
		continue
	(start, end) = (-1, -1)
	for i in range(n):
		if d[i] != 0:
			start = i
			break
	for i in range(n - 1, -1, -1):
		if d[i] != 0:
			end = i
			break
	if 0 in d[start:end] or d[start] < 0:
		print('NO')
	else:
		print('YES')


n = int(input())
INF = -10 ** 9
for _ in ' ' * n:
	q = int(input())
	(*l1,) = map(int, input().split())
	(*l2,) = map(int, input().split())
	s = set()
	r = INF
	itr = -1
	f = 1
	for i in range(q):
		if l1[i] != l2[i]:
			if r == INF:
				r = l2[i] - l1[i]
				itr = i
			elif r != l2[i] - l1[i] or i - itr != 1:
				f = 0
				break
			else:
				itr = i
	if f and r > 0 or r == INF:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t += -1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	ind = 0
	for i in range(n):
		if a[i] - b[i] != 0:
			d = a[i] - b[i]
			ind = i
			break
	if d == 0:
		print('YES')
	elif d > 0:
		print('NO')
	else:
		check = 0
		ind1 = 0
		for i in range(ind, n):
			if a[i] - b[i] != d:
				check = 1
				ind1 = i
				break
		if check == 0:
			print('YES')
		else:
			check2 = 0
			for i in range(ind1, n):
				if a[i] - b[i] != 0:
					check2 = 1
			if check2 == 0:
				print('YES')
			else:
				print('NO')


t = int(input())
zz = []
for z in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mP = []
	for i in range(n):
		mP.append(b[i] - a[i])
	cS = False
	fD = 0
	fr = False
	for el in mP:
		if el != 0:
			if fD == 0:
				fD = el
			if cS or el != fD or el < 0:
				fr = True
				break
		elif fD != 0:
			cS = True
	if fr:
		zz.append('NO')
	else:
		zz.append('YES')
for i in zz:
	print(i)


for i in range(int(input())):
	m = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dif = []
	count = 0
	flag = 0
	dif.append(0)
	for j in range(m):
		if b[j] < a[j]:
			flag = 1
		dif.append(b[j] - a[j])
	dif.append(0)
	for j in range(len(dif) - 1):
		if dif[j] != dif[j + 1]:
			count += 1
	print('YES' if (len(set(dif)) == 2 or len(set(dif)) == 1 or len(set(dif)) == 0) and count <= 2 and (flag == 0) else 'NO')


for I in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = -99999
	for i in range(n):
		if a[i] != b[i]:
			if k == -99999:
				k = b[i] - a[i]
			a[i] += abs(k)
		elif k == -99999:
			continue
		else:
			break
	if a == b:
		print('YES')
	else:
		print('NO')


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
t = N()
while t > 0:
	n = N()
	a = Y()
	b = Y()
	(l, r, ok) = (-1, -1, 1)
	for i in range(n):
		if b[i] - a[i] > 0:
			if l < 0:
				l = i
			r = i
		elif b[i] - a[i] != 0:
			ok = 0
	if ok and len(Counter([b[i] - a[i] for i in range(l, r + 1)])) > 1:
		ok = 0
	print('YNEOS'[not ok::2])
	t -= 1


def push(a, b):
	(index2, index1) = (0, 0)
	size = len(a)
	for i in range(size):
		if a[i] != b[i]:
			index2 = i
	for i in range(size):
		if a[i] != b[i]:
			index1 = i
			break
	diff = b[index1] - a[index1]
	if diff == 0:
		return 'YES'
	elif diff <= 0:
		return 'NO'
	for i in range(index1, index2 + 1):
		if a[i] + diff != b[i]:
			return 'NO'
	return 'YES'
test_cases_count = int(input())
for i in range(test_cases_count):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(push(a, b))


for _ in range(int(input())):
	n = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	(diff, flag, flag2, tem) = (0, True, True, 0)
	for i in range(n):
		diff = li2[i] - li1[i]
		if flag == False and diff > 0:
			if diff != tem or li2[i - 1] - li1[i - 1] == 0:
				flag2 = False
				break
		if diff > 0:
			if flag == True:
				tem = diff
				flag = False
		if diff != 0 and tem + li1[i] != li2[i] or diff < 0:
			flag2 = False
			break
	if flag2 == False:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	n = int(input())
	a = input().split()
	b = input().split()
	c = []
	f1 = False
	f2 = False
	f3 = True
	for i in range(n):
		if int(a[i]) == int(b[i]):
			if f1:
				f2 = True
		else:
			c.append(int(a[i]) - int(b[i]))
			if f1 == False:
				f1 = True
			if f2:
				f3 = False
	if f3:
		f4 = True
		for i in range(len(c)):
			if c[i] != c[0]:
				f4 = False
		if len(c) == 0:
			print('YES')
		elif f4 and c[0] < 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t -= 1


from collections import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	pre = 0
	for i in range(n):
		if a[i] == b[i]:
			continue
		else:
			d = a[i] - b[i]
			if d > 0:
				break
			while i < n and a[i] == b[i] + d:
				b[i] = a[i]
				i += 1
			break
	if a == b:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	mas1 = list(map(int, input().split()))
	mas2 = list(map(int, input().split()))
	flag = 0
	al = True
	p = 0
	for j in range(n):
		if mas1[j] != mas2[j]:
			if flag == 0:
				flag = 1
				p = mas1[j] - mas2[j]
				if p > 0:
					al = False
					break
			elif flag == 1:
				if p != mas1[j] - mas2[j]:
					al = False
					break
			else:
				al = False
				break
		elif flag == 1:
			flag = 2
	if al:
		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()))
	i = 0
	while i < n and a[i] == b[i]:
		i += 1
	if i == n:
		print('YES')
		continue
	k = b[i] - a[i]
	for j in range(i, n):
		if b[j] - a[j] == k:
			a[j] += k
		else:
			break
	if k <= 0 or a != b:
		print('NO')
	else:
		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()]
	t = -100
	k = 0
	cnt = 0
	for i in range(n):
		ss = b[i] - a[i]
		if ss < 0:
			cnt = 3
			break
		elif ss != k:
			k = ss
			if ss != 0:
				cnt += 1
	if cnt <= 1:
		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()))
	(x, y) = (0, 0)
	for i in range(n):
		if a[i] != b[i]:
			x = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			y = i
			break
	if x <= y:
		(z, k) = (0, b[x] - a[x])
		for i in range(x, y + 1):
			if a[i] > b[i] or b[i] - a[i] != k:
				z = -1
				break
		if z == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


num = int(input())
output = []

def func(arr1, arr2):
	stage = 1
	offset = None
	for i in range(0, len(arr1)):
		if arr1[i] == arr2[i] and (stage == 1 or stage == 3):
			pass
		elif stage == 1 and arr1[i] != arr2[i]:
			stage = 2
			offset = arr2[i] - arr1[i]
			if arr2[i] < arr1[i]:
				return 'NO'
		elif stage == 2 and arr1[i] + offset == arr2[i]:
			pass
		elif arr1[i] == arr2[i] and stage == 2:
			stage = 3
		else:
			return 'NO'
	return 'YES'
for i in range(num):
	size = int(input())
	arr1 = input().split()
	for i in range(len(arr1)):
		arr1[i] = int(arr1[i])
	arr2 = input().split()
	for i in range(len(arr2)):
		arr2[i] = int(arr2[i])
	output.append(func(arr1, arr2))
for i in output:
	print(i)


t = int(input())

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


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()))
	f = []
	p = None
	for d in (x - y for (x, y) in zip(a, b)):
		if d != p and (d != 0 or f):
			f.append(d)
		p = d
	while f and f[-1] == 0:
		f.pop()
	print('YES' if not f or (len(f) == 1 and f[0] < 0) else 'NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	newy = []
	for s in range(n):
		newy.append(b[s] - a[s])
	newy = [0] + newy
	newy.append(0)
	outy = []
	preffy = newy[0]
	for s in range(1, len(newy)):
		if newy[s] == newy[s - 1]:
			preffy += newy[s]
		else:
			outy.append(preffy)
			preffy = newy[s]
	if len(outy) < 3:
		outy.append(preffy)
	if len(outy) == 1:
		print('YES')
	elif outy[0] == 0 and outy[1] >= 0 and (outy[2] == 0) and (len(outy) == 3):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	f = 0
	if li1 == li2:
		print('YES')
	else:
		li3 = []
		for i in range(n):
			if li2[i] - li1[i] < 0:
				f = 1
				break
			else:
				li3.append(li2[i] - li1[i])
		if f == 1:
			print('NO')
		else:
			k = 10000000.0
			f = 0
			k1 = None
			t = []
			for i in range(n):
				if li3[i] != 0:
					k = i
					break
			for i in range(n - 1, -1, -1):
				if li3[i] != 0:
					k1 = i
					break
			for i in range(k, k1 + 1):
				if li3[i] == 0:
					f = 1
					break
				else:
					t.append(li3[i])
			if k1 == None:
				if len(set(t)) == 1:
					print('YES')
				else:
					print('NO')
			if f == 1:
				print('NO')
			elif len(set(t)) == 1:
				print('YES')
			else:
				print('NO')


for rpt in range(int(input())):
	length = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	fn = [0 for x in range(length)]
	for i in range(length):
		fn[i] = b[i] - a[i]
	same = True
	for i in range(length):
		if fn[0] != fn[i]:
			same = False
	if same == True and fn[0] >= 0:
		print('YES')
	else:
		l = -1
		k = -1
		for i in range(length):
			if fn[i] != 0:
				l = i
				k = fn[i]
				break
		if k < 0:
			print('NO')
		else:
			r = length - 1
			for i in range(l + 1, length):
				if fn[i] != k:
					r = i - 1
					break
			solvable = True
			for i in range(r + 1, length):
				if fn[i] != 0:
					solvable = False
			if solvable == True:
				print('YES')
			else:
				print('NO')


t = int(input())
tests = []
for i in range(t):
	n = int(input())
	a = []
	b = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tests.extend((a, b))
output_lst = []
for i in range(0, len(tests), 2):
	delta = 0
	start = -1
	for j in range(len(tests[i])):
		diff = tests[i + 1][j] - tests[i][j]
		if diff < 0:
			output_lst.append('NO')
			break
		elif diff > 0:
			if delta == 0:
				delta = diff
				start = j
			elif delta == diff:
				if start == j - 1:
					start = j
				else:
					output_lst.append('NO')
					break
			elif delta != diff:
				output_lst.append('NO')
				break
		elif diff == 0:
			if start == -1:
				continue
			elif start == j - 1:
				start = -2
	else:
		output_lst.append('YES')
for i in output_lst:
	print(i)


t = int(input())
for ij in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(0, n):
		c.append(b[i] - a[i])
	i = 0
	t = 0
	tag = 0
	while i < n:
		if c[i] < 0:
			tag = 1
			break
		if c[i] != 0 and t == 0:
			t = 1
			while i + 1 < n and c[i + 1] == c[i]:
				i += 1
			i += 1
		elif c[i] != 0:
			tag = 1
			break
		else:
			i += 1
	if tag == 1:
		print('NO')
	else:
		print('YES')


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


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 1
	f1 = 0
	k = 0
	f2 = 0
	for i in range(n):
		if a[i] > b[i]:
			flag = 0
			break
		elif a[i] < b[i]:
			if f2 == 1:
				flag = 0
				break
			if f1 == 0:
				k = b[i] - a[i]
			if b[i] - a[i] == k:
				f1 = 1
			elif b[i] - a[i] != k:
				flag = 0
				break
		elif a[i] == b[i]:
			if f1 == 1:
				f2 = 1
	if flag == 1:
		print('YES')
	else:
		print('NO')


from itertools import starmap
for _ in range(int(input())):
	n = int(input())
	a = list(starmap(int.__sub__, zip(map(int, input().split()), map(int, input().split()))))
	try:
		ai = 0
		while not ai:
			ai = a.pop()
	except IndexError:
		ai = -1
		a.append(ai)
	a.append(ai)
	i = a.index(ai)
	if a == [0] * i + [ai] * (len(a) - i) and ai < 0:
		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()))
	diff = -1
	for i in range(n):
		if a[i] == b[i]:
			if diff == -1:
				continue
			else:
				diff = 10 ** 9
		else:
			if diff == -1:
				diff = b[i] - a[i]
				if diff < 0:
					print('NO')
					break
			if diff != -1:
				if diff == b[i] - a[i]:
					continue
				else:
					print('NO')
					break
	else:
		print('YES')


t = int(input())
while t > 0:
	size = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	diff = 0
	for i in range(size):
		if flag == 0:
			if b[i] - a[i] > 0:
				diff = b[i] - a[i]
				flag = 1
			elif b[i] - a[i] < 0:
				flag = -1
				break
		elif flag == 1:
			temp = b[i] - a[i]
			if temp == 0:
				flag = 2
			elif temp != diff:
				flag = -1
				break
		elif flag == 2:
			if b[i] - a[i] != 0:
				flag = -1
				break
	if flag == -1:
		print('NO')
	else:
		print('YES')
	t -= 1


test = int(input())
for _ in range(test):
	arrlen = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	gaming = False
	for i in range(arrlen):
		c = b[i] - a[i]
		if c < 0:
			gaming = True
			break
		elif c > 0:
			if d == 0:
				d = c
			elif c != d or b[i - 1] - a[i - 1] != d:
				gaming = True
				break
	if gaming:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	else:
		(l, l1) = ([], [])
		c = 0
		for i in range(n):
			if a[i] != b[i]:
				l.append(b[i] - a[i])
				l1.append(i)
		for i in range(1, len(l1)):
			if l1[i] - l1[i - 1] > 1:
				c += 1
			else:
				continue
		c1 = 0
		for i in range(len(l)):
			if l[i] < 0:
				c1 += 1
			else:
				c1 += 0
		if c1 == 0 and len(set(l)) == 1 and (c == 0):
			print('YES')
		else:
			print('NO')
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp = 0
	for j in range(n):
		b[j] = b[j] - a[j]
		if b[j]:
			temp = b[j]
	if not temp:
		print('YES')
	elif temp < 0:
		print('NO')
	else:
		for j in range(n):
			if b[j] != temp and b[j] != 0:
				print('NO')
				break
		else:
			i1 = b.index(temp)
			b.reverse()
			i2 = n - b.index(temp) - 1
			b.reverse()
			for j in range(i1, i2 + 1):
				if b[j] != temp:
					print('NO')
					break
			else:
				print('YES')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [a[i] - b[i] for i in range(n)]
	if any((c[i] > 0 for i in range(n))):
		print('NO')
		continue
	sss = set(c)
	if 0 in sss and len(sss) == 2 or len(sss) == 1:
		flag = False
		for i in range(1, n):
			if c[i] != c[i - 1]:
				if flag and c[i]:
					print('NO')
					break
				flag = True
		else:
			print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	C = []
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for k in range(n):
		c = B[k] - A[k]
		C.append(c)
	while True:
		if len(C) == 0 or C[0] != 0:
			break
		else:
			C.remove(C[0])
	C.reverse()
	while True:
		if len(C) == 0 or C[0] != 0:
			break
		else:
			C.remove(C[0])
	if C == []:
		print('YES')
	elif any((x < 0 for x in C)):
		print('NO')
	elif all((x == C[0] for x in C)):
		print('YES')
	else:
		print('NO')


n = int(input())
for j in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = True
	l = False
	k = -1
	for i in range(m):
		if a[i] == b[i]:
			l = False
			continue
		elif k == -1 and a[i] < b[i]:
			k = b[i] - a[i]
			l = True
		elif a[i] + k == b[i] and l:
			continue
		else:
			f = False
			break
	if f:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	diff = []
	ind = []
	a = True
	b = True
	n = int(input())
	string1 = input().split()
	string2 = input().split()
	for j in range(n):
		if string1[j] != string2[j]:
			difference = int(string2[j]) - int(string1[j])
			if difference != 0:
				diff.append(difference)
				ind.append(j)
	for k in range(1, len(diff)):
		if diff[0] != diff[k]:
			a = False
	for l in range(len(diff)):
		if int(diff[l]) < 0:
			b = False
	if diff == []:
		print('YES')
	elif int(ind[-1]) - int(ind[0]) == len(ind) - 1 and a == True and (b == True):
		print('YES')
	else:
		print('NO')


t = int(input())
for daf in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cs = 0
	f = True
	el = -1
	for i in range(n):
		if b[i] - a[i] < 0:
			f = False
			break
		if b[i] - a[i] != 0:
			if cs == 0:
				cs = 1
				el = b[i] - a[i]
			elif cs == 1:
				if b[i] - a[i] != el:
					f = False
					break
			else:
				f = False
				break
		elif cs == 1:
			cs = 2
	if f:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = []
	check = 0
	k = 0
	for j in range(0, n):
		if b[j] - a[j] < 0:
			check = 1
		if len(c) == 0 or c[len(c) - 1] != b[j] - a[j]:
			c.append(b[j] - a[j])
	if check == 0 and (len(c) == 3 and c[0] == 0 and (c[len(c) - 1] == 0) or (len(c) == 2 and c[0] == 0) or (len(c) == 2 and c[len(c) - 1] == 0) or (len(c) == 1)):
		print('YES')
	else:
		print('NO')


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	n = int_input()
	a = list_input()
	b = list_input()
	start = False
	prev = -1
	diff = -1
	flag = 0
	for i in range(n):
		if a[i] != b[i] and a[i] < b[i] and (start == False):
			start = True
			diff = b[i] - a[i]
			prev = i
		elif a[i] != b[i] and b[i] - a[i] == diff and (start == True) and (prev == i - 1):
			prev = i
		elif a[i] == b[i]:
			continue
		else:
			flag = 1
	if flag == 0:
		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()))
	d = []
	for i in range(n):
		d.append(a[i] - b[i])
	pos = []
	for i in range(len(d)):
		if d[i] != 0:
			pos.append(i)
	test1 = all([pos[i + 1] - pos[i] == 1 for i in range(len(pos) - 1)])
	test2 = all([x <= 0 for x in d])
	if len(set(d)) == 1 and test2:
		print('YES')
	elif len(set(d)) == 2 and test1 and test2 and (0 in d):
		print('YES')
	else:
		print('NO')


def operation(array1, array2, n):
	i = 0
	j = n - 1
	while i < n and array1[i] == array2[i]:
		i += 1
	while j >= 0 and array1[j] == array2[j]:
		j -= 1
	if i == n:
		return True
	k = array2[i] - array1[i]
	if k > 0:
		for a in range(i, j + 1):
			if array2[a] - array1[a] != k:
				return False
		return True
	else:
		return False
t = int(input())
for i in range(t):
	n = int(input())
	array1 = input().split()
	array2 = input().split()
	for j in range(n):
		array1[j] = int(array1[j])
		array2[j] = int(array2[j])
	if operation(array1, array2, n):
		print('YES')
	else:
		print('NO')


from itertools import groupby
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = [b[i] - a[i] for i in range(0, n)]
	gb = [list(set(g))[0] for (l, g) in groupby(ans)]
	oo = True
	kk = 0
	for i in range(0, len(gb)):
		if gb[i] < 0:
			oo = False
			break
		if gb[i] > 0:
			kk += 1
		if kk > 1:
			oo = False
			break
	if oo:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	p = 'YES'
	first = 0
	subEnd = False
	for (a, b) in zip(A, B):
		if b - a < 0:
			p = 'NO'
			break
		elif b - a == 0:
			if first != 0:
				subEnd = True
		elif subEnd:
			p = 'NO'
			break
		elif first == 0:
			first = b - a
		elif first != b - a:
			p = 'NO'
			break
	print(p)


def push(a, b):
	l = []
	ans = True
	for i in range(n):
		l.append(b[i] - a[i])
	index = 0
	count = 0
	num = l[0]
	err = l[0]
	if num < 0:
		ans = False
	else:
		while index != n - 1:
			index = index + 1
			if l[index] == num:
				continue
			else:
				num = l[index]
				if num < 0:
					ans = False
				count = count + 1
				if count > 1:
					if num != err:
						ans = False
	if err == 0:
		if count <= 2 and ans == True:
			print('YES')
		else:
			print('NO')
	elif count == 1 and ans == True and (l.count(0) != 0):
		print('YES')
	elif count == 0 and ans == True:
		print('YES')
	else:
		print('NO')
test_cases_count = int(input())
for i in range(test_cases_count):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	push(a, b)


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


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	l = -1
	r = -1
	summ = -1
	for j in range(n):
		if a[j] != b[j]:
			if l == -1:
				l = j
			r = j
	summ = b[l] - a[l]
	pos = True
	for k in range(r - l + 1):
		if b[l + k] - a[l + k] != summ:
			pos = False
			break
	if pos == True:
		if summ >= 1 or l == -1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
INF = 10 ** 20
I = lambda : list(map(int, input().split()))
from collections import defaultdict as dd
from math import gcd
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	a = I()
	b = I()
	aa = -1
	k = 0
	ans = 'YES'
	for i in range(n):
		a[i] -= b[i]
		if a[i]:
			k = a[i]
			if aa == -1:
				aa = i
		if a[i] > 0:
			ans = 'NO'
	for i in range(aa, n):
		if a[i]:
			a[i] += -k
		else:
			break
	for i in range(n):
		if a[i]:
			ans = 'NO'
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	k = list(map(int, input().split()))
	(x, c) = ([], 0)
	x.append(0)
	for i in range(n):
		x.append(k[i] - p[i])
	x.append(0)
	for i in range(len(x) - 1):
		if x[i] != x[i + 1]:
			c += 1
	print('YES' if c <= 2 and sorted(x)[0] == 0 else 'NO')


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	b = list(rint())
	c = []
	for i in range(n):
		c.append(b[i] - a[i])
	s = 0
	v = 0
	tg = 0
	for i in range(n):
		if c[i] != 0:
			if tg == 1:
				print('NO')
				break
			if v != 0:
				if v != c[i]:
					print('NO')
					break
			else:
				v = c[i]
		elif v != 0:
			tg = 1
	else:
		if v < 0:
			print('NO')
		else:
			print('YES')


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))
for i in range(I()):
	n = I()
	a = L()
	b = L()
	ans = 'YES'
	k = [0] * n
	x = 0
	for i in range(n):
		k[i] = b[i] - a[i]
		if k[i] < 0:
			ans = 'NO'
			break
	for i in range(1, n):
		if k[i] != k[i - 1]:
			x += 1
	if k[0] == 0:
		x -= 1
	if k[-1] == 0:
		x -= 1
	if x > 0:
		ans = 'NO'
	print(ans)


tc = int(input())
for _ in range(tc):
	length = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	push = 0
	bad = False
	for i in range(length):
		diff = b[i] - a[i]
		if diff < 0:
			bad = True
			break
		elif diff > 0:
			if push == 0:
				push = diff
			elif diff != push or b[i - 1] - a[i - 1] != push:
				bad = True
				break
	if bad:
		print('NO')
	else:
		print('YES')


def solve(n, la, lb):
	k = 0
	kk = 0
	idx1 = 0
	idx2 = 0
	for i in range(n):
		if la[i] != lb[i]:
			k = lb[i] - la[i]
			idx1 = i
			break
	for j in range(n - 1, -1, -1):
		if la[j] != lb[j]:
			kk = lb[j] - la[j]
			idx2 = j
			break
	if k != kk:
		return 'NO'
	if k < 0:
		return 'NO'
	for i in range(idx1, idx2 + 1):
		if lb[i] - la[i] != k:
			return 'NO'
	return 'YES'
tc = int(input())
for _ in range(tc):
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	print(solve(n, la, lb))


from sys import stdin

def input():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
for _ in range(input()):
	n = input()
	a = linput()
	b = linput()
	r = l = k = -1
	c = False
	for i in range(n):
		if r == -1 and a[i] != b[i]:
			r = i
			k = b[i] - a[i]
			if k < 0:
				print('NO')
				c = True
				break
		if a[i] == b[i] and r != -1 and (l == -1):
			l = i
		if a[i] != b[i] and r != -1 and (l != -1):
			print('NO')
			c = True
			break
		if b[i] - a[i] != k and r != -1 and (l == -1):
			print('NO')
			c = True
			break
	if not c:
		print('YES')


t = int(input())
for tt in range(t):
	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]:
			flag = False
			break
	if flag:
		print('YES')
		continue
	ss = set()
	start = 0
	end = n - 1
	while start < end:
		if arr[start] == brr[start]:
			start += 1
		elif arr[end] == brr[end]:
			end -= 1
		else:
			break
	flag = True
	for i in range(start, end + 1):
		if arr[i] > brr[i]:
			flag = False
			break
	if not flag:
		print('NO')
		continue
	ss = set()
	for i in range(start, end + 1):
		ss.add(brr[i] - arr[i])
	if len(ss) > 1:
		print('NO')
	else:
		print('YES')


from itertools import groupby

def solve(as_, bs):
	if len(as_) == 1 and bs[0] > as_[0]:
		return 'YES'
	diffs = [b - a for (a, b) in zip(as_, bs)]
	if any((d < 0 for d in diffs)):
		return 'NO'
	groups = [a for (a, _) in groupby(diffs)]
	if len(groups) == 1:
		return 'YES'
	if len(groups) == 4:
		return 'NO'
	if groups[0] == 0:
		groups = groups[1:]
	if groups and groups[-1] == 0:
		groups = groups[:-1]
	return 'YES' if len(groups) < 2 else 'NO'
for _ in range(int(input())):
	n = int(input())
	as_ = [int(x) for x in input().split()]
	bs = [int(x) for x in input().split()]
	print(solve(as_, bs))


def check(a, b):
	l = len(a)
	c = 0
	f = 0
	f2 = 0
	for j in range(0, l, 1):
		if a[j] != b[j]:
			c += 1
			if f2 == 0:
				f = 1
				k = b[j] - a[j]
				if c == 1:
					p = k
				if p != k:
					return 0
				if k < 0:
					return 0
			else:
				return 0
		if a[j] == b[j] and f == 1:
			f2 = 1
	return 1
t = int(input())
for i in range(0, t, 1):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	z = check(a, b)
	if z == 1:
		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 = []
	for i in range(N):
		C.append(A[i] - B[i])
	temp = 0
	for j in range(N):
		c = C[j]
		if c > 0:
			print('NO')
			temp = 1
			break
	if temp == 0:
		counta = 0
		countb = 1
		countz = 0
		flag = 0
		for k in range(N):
			if counta != 0:
				if C[k] == 0:
					countz += 1
				elif C[k] != check:
					print('NO')
					flag = 1
					break
				elif countz != 0:
					print('NO')
					flag = 1
					break
			if C[k] != 0:
				counta += 1
				check = C[k]
		if flag == 0:
			print('YES')


class Stack:

	def __init__(self, size):
		self.top = -1
		self.arr = [None] * size

	def Push(self, data):
		self.top += 1
		self.arr[self.top] = data

	def Pop(self):
		x = self.arr[self.top]
		self.arr[self.top] = None
		self.top -= 1
		return x

	def Top(self):
		return self.arr[self.top]

	def Size(self):
		return self.Top + 1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = Stack(2)
	index = None
	maragya = 0
	for i in range(n):
		if a[i] != b[i]:
			if index == None:
				index = i
				diff.Push(b[i] - a[i])
				if diff.Top() < 1:
					maragya = 1
					break
			elif index != i - 1 or diff.Top() != b[i] - a[i]:
				maragya = 1
				break
			elif index == i - 1:
				index = i
	if maragya == 1:
		print('NO')
	else:
		print('YES')


x = int(input())
for i in range(x):
	y = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	x = 0
	ot = 1
	u = 1
	for i2 in range(y):
		if a1[i2] != a2[i2] and x != 0:
			if a1[i2] - a2[i2] != x:
				print('NO')
				ot = 0
				break
		elif a1[i2] - a2[i2] > 0:
			print('NO')
			ot = 0
			break
		elif a1[i2] != a2[i2] and x == 0:
			x = a1[i2] - a2[i2]
			u = 0
		elif a1[i2] == a2[i2] and u == 0:
			u = 2
		if a1[i2] != a2[i2] and u == 2:
			print('NO')
			ot = 0
			break
	if ot == 1:
		print('YES')


T = int(input())
for t in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	step = 0
	C = 0
	flag = True
	for i in range(n):
		c = b[i] - a[i]
		if step == 0 and c != 0:
			C = c
			step = 1
		elif step == 1 and c != C:
			if c != 0:
				flag = False
			else:
				step = 2
		elif step == 2 and c != 0:
			flag = False
	if C < 0:
		flag = False
	if flag:
		print('YES')
	else:
		print('NO')


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


def start():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	delta_old = -1
	start = True
	finish = False
	for i in range(n):
		(x, y) = (a[i], b[i])
		delta = y - x
		if delta < 0:
			return 'NO'
		elif delta == 0 and start:
			continue
		elif delta != 0 and finish:
			return 'NO'
		elif delta_old == -1:
			delta_old = delta
			start = False
		elif delta != delta_old:
			if delta != 0:
				return 'NO'
			else:
				finish = True
	return 'YES'

def main():
	t = int(input())
	for i in range(t):
		print(start())
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = 0
	z = [0] * n
	flag = 0
	count = 0
	l = 0
	r = n
	if a == b:
		print('YES')
	else:
		for i in range(n):
			if a[i] != b[i]:
				k = b[i] - a[i]
				break
		if k >= 0:
			for i in range(n):
				if a[i] != b[i]:
					a[i] += k
					z[i] = 1
					count += 1
			if count != 0:
				for i in range(n):
					if z[i] == 1:
						l = i
						break
				for i in range(n):
					if z[-1 * i - 1] == 1:
						r = -1 * i - 1
						break
		if a == b and 0 not in z[l:r] or (a == b and count in [0, 1]):
			print('YES')
		else:
			print('NO')


def singlePush(arr, n):
	if arr.count(0) == n:
		return 'YES'
	neg_count = len(list(filter(lambda x: x < 0, arr)))
	if neg_count >= 1:
		return 'NO'
	for i in range(n):
		if arr[i] != 0:
			l = i
			break
	for j in range(n - 1, -1, -1):
		if arr[j] != 0:
			r = j
			break
	if arr.count(arr[l]) == r - l + 1:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	arr = []
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		arr.append(b[i] - a[i])
	print(singlePush(arr, n))


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


from itertools import *
R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	R()
	a = [k for (k, g) in groupby((y - x for (x, y) in zip(R(), R()))) if k]
	print('YNEOS'[len(a) > 1 or min(*a, 0, 0) < 0::2])


def push(a, b, n):
	c = []
	for i in range(0, n):
		c.append(b[i] - a[i])
	m = max(c)
	if m < 0:
		return 'NO'
	ind = []
	for j in range(0, n):
		if c[j] != 0 and c[j] != m:
			return 'NO'
		elif c[j] == m:
			ind.append(j)
	size = len(ind)
	if size > 1:
		for q in range(1, size):
			if ind[q] - ind[q - 1] != 1:
				return 'NO'
	return 'YES'
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, list(input().split())))
	b = list(map(int, list(input().split())))
	print(push(a, b, n))


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = list(map(int, input().split()))
	k = 0
	for i in range(n):
		if d[i] > l[i]:
			k = d[i] - l[i]
			for j in range(i, n):
				if l[j] < d[j]:
					l[j] += k
				else:
					break
			break
	if l == d:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	p = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	n = 0
	for i in range(p):
		c = m[i] - l[i]
		if c < 0:
			n = 1
			break
		elif c > 0:
			break
	if n == 0:
		d = 0
		g = 1
		for j in range(i + 1, p):
			if m[j] - l[j] == 0:
				d += 1
			elif m[j] - l[j] == c and d == 0:
				g = 1
			else:
				g += 1
				break
		if g < 2:
			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()))
	(l, last) = ([], 0)
	chk = True
	for i in range(n):
		if b[i] < a[i]:
			chk = False
			break
		x = b[i] - a[i]
		if x != 0 and x != last:
			l.append(x)
		last = x
	if len(l) <= 1 and chk:
		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()))
	k = 0
	c = []
	d = []
	m = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			k += 1
			if a[i] - b[i] > 0:
				m += 1
			d.append(a[i] - b[i])
		elif k > 0:
			c.append(k)
			k = 0
	if k > 0:
		c.append(k)
	if len(c) == 1 and m == 0:
		if len(list(set(d))) == 1:
			print('YES')
		else:
			print('NO')
	elif len(c) == 0 and m == 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 == b:
		print('YES')
	else:
		c = []
		first = True
		ans = True
		for i in range(n):
			c.append(b[i] - a[i])
			if c[i] > 0 and first:
				first = False
				r = c[i]
			elif c[i] > 0 and (not first):
				if r != c[i]:
					ans = False
					break
			elif c[i] < 0:
				ans = False
				break
			elif c[i] == 0:
				r = 0
		if ans:
			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 = []
	p = True
	k = []
	for i in range(n):
		x = b[i] - a[i]
		if x < 0:
			p = False
			break
		elif x > 0:
			c.append(x)
			k.append(i)
	if len(set(c)) > 1:
		p = False
	if k and sorted(k) != list(range(min(k), max(k) + 1)):
		p = False
	print('YES' if p else 'NO')


def check(a, b):
	diff = []
	for i in range(len(a)):
		diff.append(a[i] - b[i])
	stage = 0
	differ = 0
	for i in range(len(diff)):
		if diff[i] == 0 and stage == 0:
			stage = 1
			continue
		if diff[i] == 0 and stage == 1:
			continue
		if diff[i] != 0 and stage == 0:
			differ = diff[i]
			if differ > 0:
				return 'NO'
			stage = 2
			continue
		if diff[i] != 0 and stage == 1:
			differ = diff[i]
			if differ > 0:
				return 'NO'
			stage = 2
			continue
		if stage == 2 and diff[i] != 0:
			if differ != diff[i]:
				return 'NO'
			continue
		if stage == 2 and diff[i] == 0:
			stage = 3
			continue
		if stage == 3 and diff[i] != 0:
			return 'NO'
	return 'YES'
test_cases = int(input())
for i in range(test_cases):
	size = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	print(check(a, b))


from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	count = 0
	i = 0
	while i < n:
		if l1[i] != l2[i]:
			j = i
			count += 1
			if count == 2:
				break
			seti = set()
			while l1[j] != l2[j]:
				seti.add(l2[j] - l1[j])
				j += 1
				if j == n:
					break
			i = j
			if j == n:
				break
		else:
			i += 1
	if count == 1:
		if len(seti) == 1:
			z = seti.pop()
			if z > 0:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif count == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(b[i] - a[i])
	ans = True
	found = 0
	val = 0
	for i in c:
		if i < 0:
			ans = False
			break
		if i != 0 and found == 0:
			found = 1
			val = i
		if i == 0 and found == 1:
			found = 2
		if i != 0 and found == 1 and (i != val):
			ans = False
			break
		if i != 0 and found == 2:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = [0 for i in range(n)]
	b = [0 for i in range(n)]
	ar = map(int, input().split())
	br = map(int, input().split())
	a = list(ar)
	b = list(br)
	c = [b[i] - a[i] for i in range(0, n)]
	aa = 0
	for i in range(0, n):
		if c[i] < 0:
			aa = 3
	c.insert(n, 0)
	c.insert(0, 0)
	for i in range(0, n + 1):
		if c[i] != c[i + 1]:
			aa = aa + 1
	if aa > 2:
		print('NO')
	else:
		print('YES')


k = int(input())
for _ in range(k):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	else:
		k = 0
		index = 0
		for i in range(n):
			if a[i] != b[i]:
				k = b[i] - a[i]
				index = i
				break
		if k < 0:
			print('NO')
		else:
			rest = -1
			for j in range(index + 1, n):
				if b[j] - a[j] == k:
					index = j
				else:
					rest = j
					break
			good = 1
			if rest != -1:
				for i in range(rest, n):
					if b[i] != a[i]:
						good = 0
						break
			if good:
				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()))
	f = 0
	k = 0
	flag = False
	ind = n
	for i in range(n):
		if b[i] - a[i] != 0 and b[i] > a[i] and (not flag):
			k = b[i] - a[i]
			flag = True
		if b[i] < a[i]:
			f = 1
			break
		if flag:
			if b[i] - a[i] != k:
				flag = False
				ind = i
				break
	for i in range(ind, n):
		if b[i] - a[i] != 0:
			f = 1
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = -1
	r = -1
	k = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
		continue
	for i in range(n):
		if a[i] != b[i]:
			l = i
			break
	for i in range(n - 1, l - 1, -1):
		if a[i] != b[i]:
			r = i
			break
	k = b[l] - a[l]
	f = True
	if k <= 0:
		f = False
		print('NO')
		continue
	for i in range(l + 1, r + 1):
		if b[i] - a[i] != k:
			print('NO')
			f = False
			break
	if f:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	li = []
	f = 0
	c = 0
	for j in range(n):
		if a[j] > b[j] or (a[j] < b[j] and c == 2):
			f = 1
			break
		elif b[j] > a[j]:
			li.append(b[j] - a[j])
			c = 1
		elif a[j] == b[j] and c == 1:
			c = 2
	li = set(li)
	if len(li) > 1 or f == 1:
		print('NO')
	else:
		print('YES')


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


def Single_push(a, b, n):
	l = 0
	r = 0
	if a == b:
		return 'YES'
	for j in range(n):
		if a[j] == b[j]:
			l += 1
		if int(a[j]) != int(b[j]):
			break
	for s in range(n):
		if int(a[s]) != int(b[s]):
			r += 1
	r = r + l
	k = abs(b[l] - a[l])
	for index in range(l, r):
		a[index] = a[index] + k
	if a == b:
		return 'YES'
	else:
		return 'NO'
test_cases = int(input())
for i in range(test_cases):
	n = int(input())
	a = input().split()
	b = input().split()
	for m in range(n):
		a[m] = int(a[m])
		b[m] = int(b[m])
	print(Single_push(a, b, n))


t = int(input())
qwe = []
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	check = [x - y for (x, y) in zip(b, a)]
	check_1 = [x for x in check if x >= 0]
	setting = set(check)
	if len(check_1) < len(check):
		answer = 'NO'
	elif len(setting) == 2 and 0 in setting:
		check_value = list(setting)[-1]
		indexes = [i for (i, x) in enumerate(check) if x == check_value]
		if indexes == list(range(indexes[0], indexes[-1] + 1)):
			answer = 'YES'
		else:
			answer = 'NO'
	elif len(setting) > 2:
		answer = 'NO'
	elif len(setting) == 1:
		answer = 'YES'
	else:
		answer = 'NO'
	t -= 1
	qwe.append(answer)
for value in qwe:
	print(value)


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().strip().split()]
	b = [int(i) for i in input().strip().split()]
	inx = []
	for i in range(n):
		if a[i] != b[i]:
			inx.append(i)
	if len(inx) == 0:
		print('YES')
	else:
		k = abs(a[inx[0]] - b[inx[0]])
		l = inx[0]
		r = inx[len(inx) - 1]
		for i in range(l, r + 1):
			a[i] = a[i] + k
		f = 0
		for i in range(n):
			if a[i] != b[i]:
				print('NO')
				f = 1
				break
		if not f:
			print('YES')


from sys import *

def solve(a, b, n):
	temp = a[0] - b[0]
	c = [temp]
	for i in range(1, n):
		val = a[i] - b[i]
		if val != temp:
			c.append(val)
		temp = val
	if len(c) > 3:
		return False
	if len(c) == 3:
		if c[0] == 0 and c[-1] == 0 and (c[1] <= 0):
			return True
		return False
	if len(c) == 2:
		if c[0] == 0 and c[-1] <= 0 or (c[-1] == 0 and c[0] <= 0):
			return True
		return False
	if len(c) == 1:
		if c[0] <= 0:
			return True
		return False
test = 1
test = int(input())
for t in range(0, test):
	n = int(input())
	arr = [int(x) for x in input().split()]
	brr = [int(x) for x in input().split()]
	ans = solve(arr, brr, n)
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
l = []
p = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	end = 0
	begin = 0
	f = 0
	if a == b:
		print('YES')
	elif a != b:
		for j in range(n):
			x = b[j] - a[j]
			l.append(x)
		while l[begin] == 0:
			begin += 1
		end = -1
		while l[end] == 0:
			end -= 1
		y = end + len(l)
		for k in range(begin, y + 1):
			p.append(l[k])
		z = p.count(p[0])
		for m in range(len(p)):
			if p[m] < 0 or z != len(p):
				f = 1
			else:
				f = 0
		if f == 1:
			print('NO')
		elif z == len(p):
			print('YES')
		p.clear()
		l.clear()


t = int(input())
for i in range(t):
	n = int(input())
	f = 0
	k = 0
	p = 0
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	for i in range(n):
		if l1[i] > l2[i]:
			print('NO')
			p = 1
			break
		elif l1[i] < l2[i] and f == 0:
			f = 1
			k = l1[i] - l2[i]
		elif l1[i] < l2[i] and f == 1 and (l1[i] - l2[i] != k):
			print('NO')
			p = 1
			break
		elif l1[i] == l2[i] and f == 1:
			f = 2
		elif l1[i] < l2[i] and f == 2:
			print('NO')
			p = 1
			break
	if p == 0:
		print('YES')


import math
t = int(input())
for f in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = [0] * n
	for i in range(n):
		cnt[i] = b[i] - a[i]
	u = [True] * n
	(l, r) = (0, 0)
	for i in range(n):
		if cnt[i] != 0:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if cnt[i] != 0:
			r = i
			break
	el = cnt[l]
	ans = True
	for i in range(l, r + 1):
		if cnt[i] != el or cnt[i] < 0:
			ans = False
	if ans:
		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 = []
	for i in range(n):
		c.append(b[i] - a[i])
	ser = list(set(c))
	ser.sort()
	if ser == [0]:
		print('YES')
	elif len(ser) > 2:
		print('NO')
	elif len(ser) == 1:
		if ser[0] > 0:
			print('YES')
		else:
			print('NO')
	elif ser[0] != 0:
		print('NO')
	else:
		k = []
		for i in range(len(c)):
			if c[i] != 0:
				k.append(i)
		flag = True
		for j in range(len(k) - 1):
			if k[j + 1] - k[j] != 1:
				print('NO')
				flag = False
				break
		if flag:
			print('YES')


def examA():
	t = I()
	for _ in range(t):
		N = I()
		a = LI()
		b = LI()
		ans = 'YES'
		cur = 0
		c = 0
		for i in range(N):
			if a[i] > b[i]:
				ans = 'NO'
			if a[i] != b[i]:
				if cur != 0 and c != i - 1:
					ans = 'NO'
				c = i
				if cur == 0:
					cur = b[i] - a[i]
				elif cur != b[i] - a[i]:
					ans = 'NO'
		print(ans)
import sys
import copy
import bisect
import heapq
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

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

def LS():
	return sys.stdin.readline().split()

def S():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
inf = float('inf')
examA()


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))[:n]
	b = list(map(int, input().split(' ')))[:n]
	flag = 0
	flag1 = 0
	for i in range(n):
		if a[i] != b[i] and flag == 0:
			flag = 1
			diff = b[i] - a[i]
			if diff < 0:
				print('NO')
				flag1 = 1
				break
			else:
				a[i] = a[i] + diff
			if i < n - 1:
				if a[i + 1] == b[i + 1]:
					break
		elif a[i] != b[i] and flag == 1:
			a[i] = a[i] + diff
			if i < n - 1:
				if a[i + 1] == b[i + 1]:
					break
	if a == b:
		print('YES')
	elif a != b and flag1 == 0:
		print('NO')


n = int(input())
for i in range(n):
	x = int(input())
	ch = input()
	L1 = [int(i) for i in ch.split()]
	ch2 = input()
	L2 = [int(i) for i in ch2.split()]
	Test = False
	for i in range(x):
		if L2[i] - L1[i] > 0:
			k = L2[i] - L1[i]
			j = i
			Test = True
			break
	if Test == True:
		for i in range(j, x):
			if L1[i] == L2[i]:
				break
			else:
				L1[i] += k
	if L1 == L2:
		print('YES')
	else:
		print('NO')


from itertools import groupby
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [[key, group] for (key, group) in groupby(range(n), key=lambda i: b[i] - a[i]) if key != 0]
	if len(c) > 1:
		print('NO')
	elif len(c) == 0:
		print('YES')
	elif c[0][0] > 0:
		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()))
	d = [0] * n
	k = 0
	ans = True
	for i in range(n):
		d[i] = b[i] - a[i]
		if d[i] < 0:
			ans = False
	obv = int(d[0] != 0)
	for i in range(1, n):
		if d[i] != d[i - 1]:
			obv += 1
	obv += int(d[-1] != 0)
	if ans and obv == 2 or obv == 0:
		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()))
	diff = 0
	res = 0
	for i in range(n):
		if diff == 0:
			if a[i] == b[i]:
				pass
			else:
				diff = b[i] - a[i]
				res = 1
				if diff < 0:
					print('NO')
					break
		else:
			temp = b[i] - a[i]
			if temp == 0:
				res = 2
			elif temp != diff or res == 2:
				print('NO')
				break
			else:
				pass
	else:
		print('YES')


t = int(input())
for v in range(t):
	n = input()
	first_index = -1
	first_flag = True
	last_index = -1
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(len(a)):
		if a[i] != b[i]:
			if first_flag:
				first_index = i
				difference = b[i] - a[i]
				first_flag = False
			last_index = i
	for i in range(len(a)):
		if i >= first_index and i <= last_index:
			a[i] += difference
	if first_index == -1:
		print('YES')
		continue
	elif a == b and difference > 0:
		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()))
	c = [b[i] - a[i] for i in range(n)]
	i = 0
	if min(c) < 0:
		print('NO')
	else:
		while i < n and c[i] == 0:
			i += 1
		j = i
		while i < n and c[i] == c[j]:
			i += 1
		while i < n and c[i] == 0:
			i += 1
		if i == n:
			print('YES')
		else:
			print('NO')


def f(n, A, B):
	diff = False
	segment = []
	tam = 0
	for i in range(n):
		if A[i] != B[i]:
			segment.append(i)
			tam += 1
			if tam != 1:
				if segment[-1] - segment[-2] != 1:
					return 'NO'
			if diff == False:
				diff = B[i] - A[i]
				if diff < 0:
					return 'NO'
			elif diff != B[i] - A[i]:
				return 'NO'
	return 'YES'
t = int(input())
for __ in range(t):
	n = int(input())
	A = [int(a) for a in input().split()]
	B = [int(b) for b in input().split()]
	print(f(n, A, B))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = l = r = None
	for i in range(n):
		if a[i] - b[i] == 0:
			if l != None:
				r = i - 1
		elif a[i] > b[i]:
			l = -1
			break
		elif l == None:
			l = i
			d = a[i] - b[i]
		elif r != None or a[i] - b[i] != d:
			l = -1
			break
	if l == -1:
		print('NO')
	else:
		print('YES')


I = input
P = print
M = map
t = int(I())
for _ in range(t):
	n = int(I())
	a = M(int, I().split())
	b = M(int, I().split())
	k = -1
	c = False
	for (i, j) in zip(a, b):
		x = j - i
		if x < 0:
			print('NO')
			break
		elif x > 0:
			if k == -1:
				k = x
				c = True
			elif c == True and k != x:
				P('NO')
				break
			elif c == False:
				P('NO')
				break
		elif c == True:
			c = False
	else:
		if k >= 0 or k == -1:
			P('YES')
		else:
			print('NO')


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	n = get_int()
	lst1 = get_int_list()
	lst2 = get_int_list()
	lst3 = [0] * n
	for i in range(n):
		lst3[i] = lst2[i] - lst1[i]
	count = 0
	lst3.append(0)
	lst3.insert(0, 0)
	for i in range(n + 1):
		if lst3[i] != lst3[i + 1]:
			count += 1
	if count <= 2 and min(lst3) >= 0:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	c = [e1 - e2 for (e1, e2) in zip(b, a)]
	red = [10001]
	for e in c:
		if e != red[-1]:
			red.append(e)
	cc = Counter(red[1:])
	if len(cc) > 2 or (len(cc) == 2 and 0 not in cc.keys()):
		print('NO')
		continue
	ans = 'YES'
	for (k, v) in cc.items():
		if k != 0 and v > 1 or k < 0:
			ans = 'NO'
	print(ans)


cases = int(input())
for v in range(cases):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	f = 0
	i = 0
	occur = 0
	while i < n:
		if a[i] != b[i]:
			occur += 1
			if occur > 1:
				f = 1
				break
			diff = b[i] - a[i]
			if diff < 0:
				f = 1
				break
			for j in range(i, n):
				if diff != b[j] - a[j]:
					break
			if j == n - 1 and (a[j] == b[j] or diff == b[j] - a[j]):
				i = j
			else:
				i = j - 1
			if f == 1:
				break
		i += 1
	if f == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split(' ')
	b = input().split(' ')
	k = 0
	l = 0
	r = 0
	for e in range(n):
		dif = int(b[e]) - int(a[e])
		if dif < 0:
			print('NO')
			break
		if dif > 0:
			if k != 0:
				if k == dif:
					if r != e - 1:
						print('NO')
						break
					if r == e - 1:
						r = e
				if k != dif:
					print('NO')
					break
			if k == 0:
				k = dif
				l = e
				r = e
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	else:
		l = []
		p = []
		for j in range(0, n):
			x = b[j] - a[j]
			if x < 0 or len(p) > 2:
				break
			else:
				l.append(x)
				if x not in p:
					p.append(x)
		if len(p) > 2 or len(l) < n:
			print('NO')
		elif 0 not in l and len(p) == 2:
			print('NO')
		else:
			status = 0
			if l[0] != 0:
				for s in range(n - 1):
					if l[s + 1] - l[s] != 0:
						status += 1
				if status <= 1:
					print('YES')
				else:
					print('NO')
			else:
				for s in range(n - 1):
					if l[s + 1] - l[s] != 0:
						status += 1
				if status <= 2:
					print('YES')
				else:
					print('NO')


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def main():
	t = rsingle_int()
	for i in range(t):
		n = rsingle_int()
		a = rmult_int()
		b = rmult_int()
		res = True
		inDiff = False
		hadDiff = False
		diff = None
		for i in range(n):
			diff_i = b[i] - a[i]
			if diff_i > 0:
				if hadDiff:
					res = False
					break
				inDiff = True
				if diff != None and diff_i != diff:
					res = False
					break
				if diff == None:
					diff = diff_i
			elif diff_i == 0:
				if inDiff:
					inDiff = False
					hadDiff = True
			else:
				res = False
				break
		print('YES' if res else 'NO')
main()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(b[i] - a[i])
	cset = set(c)
	if len(cset) > 2:
		print('NO')
	elif len(cset) == 2:
		cset = list(cset)
		if 0 in cset:
			cset.remove(0)
			if n - c[::-1].index(cset[0]) - c.index(cset[0]) == c.count(cset[0]) and cset[0] > 0:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		cset = list(cset)
		print('YNEOS'[cset[0] < 0::2])


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	maxim = 1
	check = 1
	setvar = 0
	counter = 1
	for j in range(n):
		if A[j] + setvar == B[j]:
			check = check
		elif setvar == 0 and check:
			setvar = B[j] - A[j]
			if setvar < 0:
				print('NO')
				counter = 0
				break
		elif check:
			check = 0
			if A[j] != B[j]:
				counter = 0
				print('NO')
				break
			else:
				setvar = 0
		else:
			print('NO')
			counter = 0
			break
	if counter:
		print('YES')


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
	g = 0
	A = []
	B = []
	c = []
	d = []
	for j in range(n):
		if a[j] > b[j]:
			f = 1
	if f == 1:
		print('NO')
		continue
	for k in range(n):
		if a[k] != b[k]:
			A.append(a[k])
			B.append(b[k])
			c.append(k)
	for l in range(0, len(c) - 1):
		if c[l] + 1 != c[l + 1]:
			g = 1
	for m in range(len(A)):
		diff = B[m] - A[m]
		d.append(diff)
	r = set(d)
	s = list(r)
	if g == 1:
		print('NO')
		continue
	if len(s) == 1 or len(s) == 0:
		print('YES')
	elif len(s) > 1:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	(tmp, con) = (-1, False)
	for (x, y) in zip(a, b):
		if x > y:
			print('NO')
			break
		elif x < y:
			if tmp == -1:
				tmp = y - x
			elif con or tmp != y - x:
				print('NO')
				break
		elif tmp != -1:
			con = True
	else:
		print('YES')


import sys
input = sys.stdin.readline

def main():
	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 N == 1:
			if A[0] > B[0]:
				print('NO')
				continue
			else:
				print('YES')
				continue
		yes = True
		SA = []
		for i in range(N):
			SA.append(B[i] - A[i])
		count = 0
		sa = 0
		if SA[0] != 0:
			count += 1
			sa = SA[0]
		for i in range(1, N):
			if SA[i - 1] == 0 and SA[i] != 0:
				count += 1
			if SA[i] != 0 and sa == 0:
				sa = SA[i]
			if sa != 0 and SA[i] != 0 and (SA[i] != sa):
				yes = False
		if count > 1 or sa < 0:
			yes = False
		if yes:
			print('YES')
		else:
			print('NO')
main()


def solve(l, k, n):
	for t in range(n):
		if l[t] > k[t]:
			return 'NO'
		if l[t] < k[t]:
			x = k[t] - l[t]
			flag = 0
			for i in range(t, n):
				if l[i] == k[i]:
					flag = 1
				else:
					if k[i] - l[i] != x:
						return 'NO'
					if k[i] != l[i] and flag:
						return 'NO'
			return 'YES'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	print(solve(l, k, n))


def solve(l):
	state = 0
	prev = 0
	repeated = -1
	for element in l:
		if element < 0:
			return False
		if state == 0:
			if repeated < 0 and element > 0:
				repeated = element
				prev = element
				state = 1
		elif state == 1:
			if prev != element:
				if element > 0:
					return False
				elif element == 0:
					prev = element
					state = 2
		elif element != 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()))
	C = [B[j] - A[j] for j in range(len(A))]
	print('YES' if solve(C) else 'NO')


n = int(input())
for i in range(n):
	flag = 0
	l = []
	mo = []
	c = []
	m = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == b:
		print('YES')
	else:
		for i in range(0, len(a)):
			if a[i] != b[i]:
				mo.append(b[i] - a[i])
				l.append(i)
		for i in range(0, len(l) - 1):
			c.append(l[i + 1] - l[i])
		if len(l) == 1 and mo[0] > 0:
			print('YES')
		elif len(set(mo)) == 1 and mo[0] >= 0 and (len(set(c)) == 1 or len(c) == 1) and (c[0] == 1):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	new = [0]
	flag = True
	for (x1, x2) in zip(lst1, lst2):
		if x2 - x1 < 0:
			flag = False
		new.append(x2 - x1)
	new.append(0)
	count = 0
	for j in range(len(new) - 1):
		if not new[j] == new[j + 1]:
			count += 1
	if flag and count <= 2 and (not len(new) == 2):
		print('YES')
	else:
		print('NO')


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = []
	p = set()
	for i in range(n):
		if a[i] != b[i]:
			p.add(b[i] - a[i])
			x.append(i)
	p = list(p)
	if len(p) == 0:
		print('YES')
	elif len(p) == 1:
		if p[0] > 0:
			f = 1
			for i in range(1, len(x)):
				if x[i] - x[i - 1] != 1:
					f = 0
					break
			if f:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


def check_it(a, b, size):
	k = 0
	input_time = 0
	k_stack = []
	for i in range(size):
		if a[i] > b[i]:
			return 'NO'
		elif a[i] == b[i]:
			if k_stack:
				k_stack.pop()
			continue
		else:
			k = b[i] - a[i]
			if not k_stack:
				k_stack.append(k)
				input_time += 1
			elif k_stack[-1] == k:
				continue
			else:
				return 'NO'
		if input_time > 1:
			return 'NO'
	return 'YES'
n = int(input())
for i in range(n):
	x = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	print(check_it(a, b, x))


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	dif = 0
	i = 0
	count = 0
	while i < n:
		if a[i] != b[i]:
			count += 1
			if count > 1:
				break
			dif = b[i] - a[i]
			if dif >= 0:
				i += 1
				while i < n and b[i] - a[i] == dif:
					i += 1
				continue
			else:
				count = 2
				break
		i += 1
	if count <= 1:
		print('YES')
	if count >= 2:
		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()))
	j = 0
	l = 0
	r = 0
	diff1 = 0
	diff2 = 0
	count = 0
	while j < len(a):
		if a[j] != b[j]:
			l = j
			diff1 = b[j] - a[j]
			break
		j += 1
	j1 = len(a) - 1
	while j1 >= l:
		if a[j1] != b[j1]:
			r = j1
			diff2 = b[j1] - a[j1]
			break
		j1 -= 1
	if l == r:
		if diff1 < 0:
			print('NO')
		elif diff1 >= 0:
			print('YES')
	else:
		if diff1 == diff2:
			for j in range(l, r + 1):
				if a[j] != b[j] and b[j] - a[j] > 0:
					if b[j] - a[j] == diff1:
						count += 1
		if count != r - l + 1:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp = []
	cont = -1
	for (at, bt) in zip(a, b):
		diff = bt - at
		if diff < 0:
			print('NO')
			break
		elif diff > 0:
			if cont != -1:
				if cont != diff:
					print('NO')
					break
			elif temp:
				print('NO')
				break
			else:
				cont = diff
				temp.append(diff)
		else:
			cont = -1
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	i = 0
	while i != n and a[i] == b[i]:
		i += 1
	if i == n:
		print('YES')
		continue
	razn = a[i] - b[i]
	if razn > 0:
		print('NO')
		continue
	while i != n and a[i] - b[i] == razn:
		i += 1
	while i != n and a[i] == b[i]:
		i += 1
	if i == 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()))
	l = []
	k = 0
	for i in range(n):
		if a[i] != b[i]:
			k = b[i] - a[i]
			l.append(i)
	if len(l) > 0:
		if k < 0:
			print('NO')
		else:
			left = l[0]
			right = l[-1]
			for i in range(left, right + 1):
				a[i] += k
			if a == b:
				print('YES')
			else:
				print('NO')
	else:
		print('YES')


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = [0 for i in range(n)]
	for i in range(n):
		if a[i] != b[i]:
			d[i] = a[i] - b[i]
	flag = 0
	ch = 0
	ans = 'YES'
	last = 0
	for i in range(n):
		if flag == 1 and d[i] != 0:
			if d[i] != ch or last != i - 1:
				ans = 'NO'
				break
			last = i
		elif d[i] != 0:
			flag = 1
			ch = d[i]
			last = i
			if ch > 0:
				ans = 'NO'
				break
	print(ans)


import math
from fractions import Fraction as frac

def solve(case_no):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [b[i] - a[i] for i in range(n)]
	ck = True
	k = -1
	for i in range(n):
		if c[i] < 0:
			ck = False
			break
		if c[i] != 0:
			if k == -1 or k == c[i]:
				k = c[i]
			else:
				ck = False
		elif k != -1:
			k = 0
	print('YES' if ck else 'NO')
t = 1
t = int(input())
for i in range(1, t + 1):
	solve(i)


def Test():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	i = 0
	while i < n:
		if a[i] != b[i]:
			if a[i] > b[i]:
				return 0
			d = b[i] - a[i]
			i += 1
			while i < n and b[i] - a[i] == d:
				i += 1
			while i < n:
				if b[i] != a[i]:
					return 0
				i += 1
		i += 1
	return 1
t = int(input())
while t != 0:
	if Test() == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


from itertools import groupby
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = [b[i] - a[i] for i in range(n)]
	i = 0
	while i < len(count) and count[i] == 0:
		i += 1
	j = i
	while j < len(count) and count[j] == count[i] and (count[i] > 0):
		j += 1
	k = j
	while k < len(count) and count[k] == 0:
		k += 1
	if k == len(count):
		print('YES')
	else:
		print('NO')


from collections import deque
from math import ceil, floor, sqrt, gcd

def ii():
	return int(input())

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

def li():
	return list(mi())

def si():
	return input()
t = 1
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	b = li()
	f = 0
	f1 = 0
	for i in range(n):
		if a[i] != b[i]:
			break
	x = b[i] - a[i]
	if x < 0:
		f1 = 1
		print('NO')
	else:
		for j in range(i + 1, n):
			if x != b[j] - a[j]:
				f = 1
			if f:
				if a[j] != b[j]:
					print('NO')
					f1 = 1
					break
		if f1 == 0:
			print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	index = []
	flag = 0
	for i in range(0, n):
		if arr[i] > brr[i]:
			flag = 1
			break
		elif arr[i] != brr[i]:
			index.append(i)
	if flag == 1:
		print('NO')
	elif len(index) == 0:
		print('YES')
	elif len(index) == 1:
		print('YES')
	else:
		start = index[0]
		last = index[-1]
		diff = []
		for i in range(start, last + 1):
			diff.append(brr[i] - arr[i])
		if len(set(diff)) == 1:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for testcases in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [B[i] - A[i] for i in range(n)]
	MAX = max(C)
	if min(C) < 0:
		print('NO')
		continue
	if MAX == 0:
		print('YES')
		continue
	for c in C:
		if 0 < c < MAX:
			print('NO')
			break
	else:
		D = []
		for i in range(n):
			if C[i] == MAX:
				D.append(i)
		if len(D) <= 1:
			print('YES')
			continue
		for j in range(1, len(D)):
			if D[j] != D[j - 1] + 1:
				print('NO')
				break
		else:
			print('YES')


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


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	neg = False
	d = {}
	ans = 'NO'
	for i in range(n):
		if b[i] - a[i] < 0:
			neg = True
		if b[i] - a[i] != 0:
			d[b[i] - a[i]] = d.get(b[i] - a[i], 0) + 1
	if len(d) <= 1:
		c = []
		for i in range(n):
			if b[i] - a[i] in d:
				c.append(i)
		if len(c) == 0 or c[-1] - c[0] + 1 == len(c):
			ans = 'YES'
	print('NO' if neg else ans)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = False
	j = 0
	while a[j] == b[j]:
		j += 1
		if j == n:
			print('YES')
			f = True
			break
	if f:
		continue
	d = b[j] - a[j]
	if d < 0:
		print('NO')
		continue
	while b[j] - a[j] == d:
		j += 1
		if j == n:
			print('YES')
			f = True
			break
	if f:
		continue
	while b[j] == a[j]:
		j += 1
		if j == n:
			print('YES')
			f = True
			break
	if f:
		continue
	if j < n:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	N = int(stdin.readline())
	A = [int(x) for x in stdin.readline().split()]
	B = [int(x) for x in stdin.readline().split()]
	indices = []
	values = []
	flag = True
	for i in range(N):
		if A[i] != B[i]:
			if B[i] < A[i]:
				flag = False
				break
			values.append(B[i] - A[i])
			indices.append(i)
	if not flag:
		print('NO')
		continue
	if len(set(values)) > 1:
		flag = False
	for i in range(1, len(indices)):
		if indices[i] - indices[i - 1] != 1:
			flag = False
			break
	print('YES') if flag 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()))
	boo = True
	i = 0
	while i < n and A[i] == B[i]:
		i += 1
	j = 0
	while i < n and A[i] != B[i]:
		if j == 0:
			k = B[i] - A[i]
			j += 1
		if k != B[i] - A[i] or k < 0:
			boo = False
			break
		i += 1
	if boo:
		for i in range(i, n):
			if A[i] != B[i]:
				boo = False
	if boo:
		print('YES')
	else:
		print('NO')
	T -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = []
	k = []
	flag = 0
	for i in range(n):
		c = b[i] - a[i]
		if c > 0:
			f.append(c)
			if k == []:
				k.append(i)
			elif i - k[0] > 1:
				flag = 1
				break
			else:
				k.pop()
		elif c < 0:
			flag = 1
			break
	if len(set(f)) > 1 or flag:
		print('NO')
	else:
		print('YES')


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


cases = int(input())
for c in range(cases):
	n = int(input())
	a = []
	b = []
	linea = input()
	linea = linea.split(' ')
	for i in range(n):
		a.append(int(linea[i]))
	linea = input()
	linea = linea.split(' ')
	for i in range(n):
		b.append(int(linea[i]))
	l = n
	r = n
	for i in range(n):
		if a[i] != b[i]:
			l = i
			break
	if l == n:
		print('YES')
	else:
		equal_diff = a[l] - b[l]
		possible = True
		if equal_diff > 0:
			possible = False
		for i in range(l, n):
			if a[i] - b[i] == equal_diff:
				continue
			else:
				r = i
				break
		for i in range(r, n):
			if a[i] != b[i]:
				possible = False
				break
		if possible:
			print('YES')
		else:
			print('NO')


num_tests = int(input())
for i in range(num_tests):
	length = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	result = 'YES'
	delta = 0
	current = 0
	for j in range(length):
		if a[j] == b[j]:
			current += 1
		else:
			break
	for j in range(current, length):
		current += 1
		if a[j] > b[j]:
			result = 'NO'
			break
		elif a[j] < b[j]:
			if delta == 0:
				delta = b[j] - a[j]
			elif delta != b[j] - a[j]:
				result = 'NO'
				break
		else:
			break
	if result == 'YES':
		for j in range(current, length):
			if a[j] != b[j]:
				result = 'NO'
				break
	print(result)


def readint():
	return int(input())

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

def readgridint(rows):
	grid = []
	for idx in range(rows):
		col = list(map(int, input().split()))
		grid.append(col)
	return grid

def main():
	num_tests = readint()
	for test_case in range(num_tests):
		n = readint()
		A = readlistint()
		B = readlistint()
		diffs = []
		for idx in range(n):
			diffs.append(B[idx] - A[idx])
		possible = True
		runs = 0
		for (idx, diff) in enumerate(diffs):
			if diff < 0:
				possible = False
				break
			elif diff > 0:
				if idx == 0:
					runs = 1
				elif diff != diffs[idx - 1]:
					if runs >= 1 or diffs[idx - 1] != 0:
						possible = False
						break
					else:
						runs = 1
		if possible:
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = []
	for i in range(n):
		if a[i] != b[i]:
			ans.append(i)
	f = False
	for i in range(1, len(ans)):
		if ans[i] - ans[i - 1] != 1:
			f = True
	if f:
		print('NO')
	elif len(ans) == 0:
		print('YES')
	else:
		f = False
		now = a[ans[0]] - b[ans[0]]
		for i in range(1, len(ans)):
			if now != a[ans[i]] - b[ans[i]]:
				f = True
		if f or now > 0:
			print('NO')
		else:
			print('YES')


def solution(arr_a, arr_b):
	res = [y - x for (x, y) in zip(arr_a, arr_b)]
	res_set = set(res)
	if len(res_set) > 2:
		return 'NO'
	for x in set(res_set):
		if x < 0:
			return 'NO'
	if len(res_set) == 2:
		if 0 not in res_set:
			return 'NO'
	if len(res_set) == 1 and list(res_set)[0] >= 0:
		return 'YES'
	for i in range(len(res)):
		if res[i] != 0:
			l = i
			break
	for i in range(len(res) - 1, -1, -1):
		if res[i] != 0:
			r = i
			break
	my_set = set([])
	for i in range(l, r + 1):
		my_set.add(res[i])
		if len(my_set) > 1 and i < r:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	arr_a = [int(x) for x in input().split()]
	arr_b = [int(x) for x in input().split()]
	print(solution(arr_a, arr_b))


from sys import stdin

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))

def main():
	t = iin()
	while t:
		t -= 1
		n = iin()
		a = lin()
		b = lin()
		ans = 'YES'
		i = 0
		while i < n and a[i] - b[i] == 0:
			i += 1
		ch = 0
		while i < n:
			if ch:
				x = a[i] - b[i]
				if x == 0:
					pass
				else:
					ans = 'NO'
					break
				i += 1
				continue
			x = a[i] - b[i]
			if x > 0:
				ans = 'NO'
				break
			while i < n and a[i] - b[i] == x:
				i += 1
			ch = 1
		print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	lis1 = input().split()
	lis2 = input().split()
	counter = 0
	counter2 = 0
	for j in range(n):
		lis1[j] = int(lis1[j])
		lis2[j] = int(lis2[j])
		k = lis2[j] - lis1[j]
		if counter != 0 and k == 0:
			counter = 0
		if k < 0:
			counter2 = 10
		if counter == 0:
			if k != 0:
				counter2 += 1
				counter = k
		elif counter != k and k != 0:
			counter2 += 1
	if counter2 >= 2:
		print('NO')
	else:
		print('YES')


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 'YES'
	res = [0] * (n + 2)
	for i in range(n):
		res[i + 1] = b[i] - a[i]
	(res[0], res[n + 1]) = (0, 0)
	k = 0
	for i in range(n + 1):
		if res[i] != res[i + 1]:
			k += 1
		if res[i] < 0:
			k = 10
	if k > 2:
		print('NO')
	else:
		print(ans)
t = int(input())
while t:
	solve()
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dif = [y - x for (x, y) in zip(a, b)]
	s = set(dif)
	if any((x < 0 for x in dif)):
		print('NO')
		continue
	if len(s) == 1:
		print('YES')
		continue
	i = 0
	while dif[i] == 0:
		i += 1
	j = n - 1
	while dif[j] == 0:
		j -= 1
	reduce = dif[i:j + 1]
	if len(set(reduce)) == 1:
		print('YES')
	else:
		print('NO')


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	n = int(input())
	a = arrIN()
	b = arrIN()
	x = []
	for i in range(n):
		if a[i] != b[i]:
			x.append([i, b[i] - a[i]])
	for i in x:
		if i[1] < 0:
			print('NO')
			break
	else:
		if len(x) <= 1:
			print('YES')
			continue
		for i in range(1, len(x)):
			if x[i][0] != x[i - 1][0] + 1 or x[i][1] != x[i - 1][1]:
				print('NO')
				break
		else:
			print('YES')


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	changeIndex = -1
	for i in range(n):
		if a[i] != b[i]:
			changeIndex = i
			break
	if changeIndex == -1:
		print('YES')
	elif b[changeIndex] - a[changeIndex] < 0:
		print('NO')
	else:
		i = changeIndex
		possible = True
		while i < n and a[i] != b[i]:
			if b[i] - a[i] != b[changeIndex] - a[changeIndex]:
				possible = False
				break
			i += 1
		if i == n:
			print('YES')
		elif not possible:
			print('NO')
		else:
			possible = True
			for j in range(i, n):
				if a[j] != b[j]:
					possible = False
					break
			if possible:
				print('YES')
			else:
				print('NO')


results = []
for _ in range(int(input())):
	input()
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	if a == b:
		results.append('YES')
	else:
		i = 0
		for i in range(len(a)):
			if a[i] != b[i]:
				break
		j = i + 1
		for j in range(i + 1, len(a)):
			if a[j] == b[j]:
				j -= 1
				break
		if a[j + 1:] != b[j + 1:]:
			results.append('NO')
			continue
		diff = b[i] - a[i]
		if diff > 0:
			if list(map(lambda s: s + diff, a[i:j + 1])) == b[i:j + 1]:
				results.append('YES')
				continue
		results.append('NO')
for i in results:
	print(i)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = 0
	s = 0
	q = set()
	g = 0
	d = []
	for i in range(n):
		if a[i] > b[i]:
			c = 1
		elif a[i] < b[i]:
			d.append(i)
			q.add(b[i] - a[i])
		else:
			g += 1
	if g == n:
		print('YES')
	elif c == 1:
		print('NO')
	elif len(q) > 1:
		print('NO')
	else:
		f = len(d)
		if f == 1:
			print('YES')
		else:
			y = 1
			for i in range(1, f):
				if d[i] - d[i - 1] == 1:
					y += 1
			if y == f:
				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()))
	res = True
	flg = 0
	diff = 0
	for i in range(n):
		if A[i] > B[i]:
			res = False
			break
		elif A[i] == B[i]:
			if flg == 1:
				flg = 2
			continue
		elif flg == 0:
			diff = B[i] - A[i]
			flg = 1
		elif flg == 1:
			if B[i] - A[i] == diff:
				continue
			else:
				res = False
				break
		else:
			res = False
			break
	if res:
		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()))
	l = r = -1
	c = True
	for j in range(n):
		if a[j] != b[j]:
			if r == -1 and l == -1:
				r = j
			if r != -1 and l == -1 and (j != n - 1) and (a[j + 1] == b[j + 1]):
				l = j
			elif r != -1 and l == -1 and (j == n - 1):
				l = j
			elif r != -1 and l != -1:
				print('NO')
				c = False
				break
	if c:
		k = b[r] - a[r]
		if k >= 0:
			for _ in range(r, l + 1):
				if b[_] - a[_] != k:
					print('NO')
					c = False
					break
			if c:
				print('YES')
		else:
			print('NO')


r = lambda : list(map(int, input().split()))

def slve(n, a, b):
	l = 0
	r = n - 1
	diff = []
	for i in range(n):
		if a[i] != b[i]:
			l = i
			break
	for j in range(n - 1, -1, -1):
		if a[j] != b[j]:
			r = j
			break
	for i in range(l, r + 1):
		diff.append(a[i] - b[i])
	if len(set(diff)) == 1 and diff[0] <= 0:
		return 'YES'
	else:
		return 'NO'
for _ in range(int(input())):
	n = r()[0]
	a = r()
	b = r()
	print(slve(n, a, b))


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
for _ in range(int(input())):
	n = int(input())
	a = list(read())
	b = list(read())
	arr = []
	for i in range(n):
		if a[i] != b[i]:
			arr.append((i, b[i] - a[i]))
	flag = True
	s = []
	for (i, j) in arr:
		if j <= 0:
			flag = False
			break
		s.append(j)
	for i in range(1, len(arr)):
		if arr[i][0] != arr[i - 1][0] + 1:
			flag = False
			break
	if len(set(s)) >= 2:
		flag = False
	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()))
	dif = []
	temp = 0
	for i in range(n):
		if a[i] - b[i] != 0:
			dif.append(i)
			temp = b[i] - a[i]
	flag = 'YES'
	if len(dif) > 1:
		for i in range(len(dif) - 1):
			l = dif[i]
			if a[l] + temp == b[l] and temp > 0 and (dif[i] + 1 == dif[i + 1]):
				pass
			else:
				flag = 'NO'
		print(flag)
	elif len(dif) == 1:
		l = dif[0]
		if a[l] + temp == b[l] and temp >= 0:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


def single_push(a, b, n):
	l = [b[i] - a[i] for i in range(n)]
	l2 = [l[0]]
	ans = 'YES'
	count = 0
	if l[0] > 0:
		count += 1
	if l[0] < 0:
		return 'NO'
	for i in range(1, n):
		if l[i] < 0:
			return 'NO'
		if l[i] not in l2:
			l2.append(l[i])
		if l[i - 1] != l[i] and l[i - 1] != 0 and (l[i] != 0) or len(l2) > 2:
			ans = 'NO'
		if l[i - 1] != l[i]:
			count += 1
	if count > 2:
		return 'NO'
	return ans
value = []
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	value.append(single_push(a, b, n))
for i in range(len(value)):
	print(value[i])


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	ans = -1
	d = -1
	f = 0
	for i in range(n):
		if arr1[i] > arr2[i]:
			ans = 0
			break
		elif arr1[i] < arr2[i]:
			if d == -1:
				d = arr2[i] - arr1[i]
				f = 1
			elif arr2[i] - arr1[i] != d or f == 0:
				ans = 0
				break
		elif f == 1:
			f = 0
	if ans == 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	n = int(input())
	ln = [int(j) for j in input().split(' ')]
	ln2 = [int(j) for j in input().split(' ')]
	si = -1
	ei = -1
	going = False
	diff = -1
	f = True
	cn = []
	for j in range(0, len(ln)):
		if ln2[j] == ln[j]:
			continue
		if ln2[j] < ln[j]:
			f = False
		if diff == -1:
			diff = ln2[j] - ln[j]
		elif diff != ln2[j] - ln[j]:
			f = False
		cn.append(j)
	if len(cn) > 0 and cn[-1] - cn[0] > len(cn) - 1:
		f = False
	if f:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	j = k = 0
	end = flag = contin = True
	for j in range(s):
		if b[j] - a[j] > 0:
			if contin:
				if flag:
					k = b[j] - a[j]
					flag = False
				elif b[j] - a[j] != k:
					end = False
					break
			else:
				end = False
				break
		elif b[j] - a[j] == 0 and k != 0:
			contin = False
		elif b[j] - a[j] < 0:
			end = False
			break
	if end == False:
		print('NO')
	else:
		print('YES')


test_count = int(input())
for _ in range(test_count):
	m = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	i = 0
	while i < m and a[i] == b[i]:
		i += 1
	if i == m:
		print('YES')
	else:
		j = m - 1
		while j >= 0 and a[j] == b[j]:
			j -= 1
		delta = b[i] - a[i]
		if delta < 0:
			print('NO')
		else:
			i += 1
			while i <= j and b[i] - a[i] == delta:
				i += 1
			if i == j + 1:
				print('YES')
			else:
				print('NO')


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
t = intput()
for _ in range(t):
	n = intput()
	a = list(intsput())
	b = list(intsput())
	op = []
	la = []
	for i in range(n):
		if a[i] != b[i]:
			op.append(i)
			la.append(b[i] - a[i])
	if not la:
		print('YES')
		continue
	if la[0] > 0 and (len(la) <= 1 or all([x == la[0] for x in la])):
		if len(op) <= 1 or all([op[i] == op[i - 1] + 1 for i in range(1, len(op))]):
			print('YES')
			continue
	print('NO')


m = int(input())
for j in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))

	def single_push(a, b):
		L = [b[i] - a[i] for i in range(len(a))]
		k = 0
		r = 0
		for j in range(len(a)):
			if L[j] < 0:
				return print('NO')
			elif L[j] == 0 and k == 0:
				continue
			elif L[j] == 0 and k != 0:
				r = 1
				continue
			elif L[j] > 0 and k == 0:
				v = L[j]
				k = 1
				continue
			elif L[j] > 0 and r == 1:
				return print('NO')
			elif L[j] > 0 and k == 1 and (r != 1):
				if L[j] == v:
					continue
				else:
					return print('NO')
		return print('YES')
	single_push(a, b)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	l = 0
	while l < n:
		r = l
		while r < n and b[r] - a[r] == b[l] - a[l]:
			r += 1
		if b[l] - a[l] < 0:
			cnt += float('inf')
		if b[l] - a[l] != 0:
			cnt += 1
		l = r
	print(cnt <= 1 and 'YES' or 'NO')


def isconsecutive(L):
	for i in range(0, len(L) - 1):
		if L[i + 1] - L[i] != 1:
			return 'NO'
	return 'YES'

def push(L):
	if min(L) < 0:
		return 'NO'
	elif all((e == 0 for e in range(len(L)))):
		return 'YES'
	else:
		p = max(L)
		M = []
		for i in range(0, len(L)):
			if L[i] != 0 and L[i] != p:
				return 'NO'
			elif L[i] == p:
				M.append(i)
		return isconsecutive(M)
t = int(input())
for i in range(0, t):
	x = int(input())
	L = list(map(int, input().split()))
	M = list(map(int, input().split()))
	for i in range(0, len(L)):
		L[i] = M[i] - L[i]
	print(push(L))


t = int(input())
for _ in range(t):
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	diff = []
	for i in range(n):
		diff.append(lb[i] - la[i])
	if any((x < 0 for x in diff)):
		print('NO')
		continue
	pre = 0
	f = 0
	for x in diff:
		if pre != x:
			if f != 0 and x != 0:
				print('NO')
				break
			f = 1
		pre = x
	else:
		print('YES')


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


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


import sys
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp = []
	for i in range(n):
		temp.append(a[i] - b[i])
	prev = sys.maxsize
	(f, cnt) = (0, 0)
	for i in temp:
		if i > 0:
			f = 1
			break
		elif i < 0:
			if prev == sys.maxsize:
				prev = i
			elif i != prev or cnt == 1:
				f = 1
				break
		elif prev != sys.maxsize and i == 0:
			cnt = 1
	if f == 1:
		print('NO')
	else:
		print('YES')


import sys
from collections import Counter

def main():
	solns = []
	t = int(sys.stdin.readline())
	for _ in range(t):
		n = int(sys.stdin.readline())
		a = [int(x) for x in sys.stdin.readline().split(' ')]
		b = [int(x) for x in sys.stdin.readline().split(' ')]
		diff = [y - x for (x, y) in zip(a, b)]
		count = Counter(diff)
		if len(count.keys()) == 1 and list(count.keys())[0] >= 0:
			solns.append('YES')
			continue
		elem = [x for x in count if x != 0][0]
		if elem < 0:
			solns.append('NO')
			continue
		l = diff.index(elem)
		r = n - 1 - diff[::-1].index(elem)
		if len([x for x in diff[l:r + 1] if x != elem]) > 0:
			solns.append('NO')
		elif len([x for x in diff[:l] if x != 0]) > 0:
			solns.append('NO')
		elif len([x for x in diff[r + 1:] if x != 0]) > 0:
			solns.append('NO')
		else:
			solns.append('YES')
	print('\n'.join(solns))
main()


def ab():
	b = int(input())
	l = 0
	f = 0
	k = 0
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	for i in range(0, b):
		if c[i] < d[i] and k == 0:
			k = d[i] - c[i]
			f = 1
		elif c[i] == d[i] and k > 0:
			f = 2
		elif c[i] < d[i] and k != 0:
			t = d[i] - c[i]
			if t != k or f == 2:
				print('NO')
				return
		elif c[i] > d[i]:
			print('NO')
			return
	print('YES')
for i in range(0, int(input())):
	ab()


for _ in range(int(input())):
	n = int(input())
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	meta = [0]
	for i in range(n):
		meta.append(s1[i] - s2[i])
	meta.append(0)
	flag = 0
	for i in range(len(meta) - 1):
		if meta[i] != meta[i + 1]:
			flag += 1
		if meta[i] > 0:
			flag += 1000
	if flag > 2:
		print('NO')
	else:
		print('YES')


import math

def solve(a, b, n):
	diff = 0
	prev = False
	prev_diff = -1
	for j in range(n):
		if a[j] > b[j]:
			return False
		if diff > 1:
			return False
		if a[j] != b[j]:
			if prev == False:
				prev = True
				diff += 1
				prev_diff = b[j] - a[j]
			elif b[j] - a[j] != prev_diff:
				return False
		elif a[j] == b[j]:
			if prev == True:
				prev = False
		if a[j] > b[j]:
			return False
		if diff > 1:
			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 solve(a, b, n) == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if l1 == l2:
		print('YES')
	else:
		st = -1
		lst = -1
		for i in range(n):
			if l1[i] != l2[i]:
				if st == -1:
					st = i
			if st != -1 and l1[i] == l2[i]:
				lst = i
				temp = l2[i - 1] - l1[i - 1]
				break
		if st != -1 and lst == -1:
			temp = l2[n - 1] - l1[n - 1]
			lst = n
		if temp < 0:
			print('NO')
		else:
			for i in range(st, lst):
				l1[i] = l1[i] + temp
			if l1 == l2:
				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()))
	x = [b[i] - a[i] for i in range(n)]
	seen_start = False
	seen_end = False
	seen_number = None
	possible = True
	for c in x:
		if c != 0:
			if not seen_start:
				seen_start = True
				seen_number = c
				if c < 0:
					possible = False
			if seen_start and (not seen_end):
				if c != seen_number:
					possible = False
			if seen_start and seen_end:
				possible = False
		if c == 0:
			if seen_start:
				seen_end = True
	print('YES' if possible else 'NO')


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = list(map(int, input().split()))
	return (n, m)

def dva():
	(n, m) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
t = int(input())
for i in range(t):
	(n, a) = na()
	b = list(map(int, input().split()))
	c = []
	f = True
	s = set()
	for j in range(n):
		if a[j] != b[j]:
			if a[j] > b[j]:
				print('NO')
				f = False
				break
			c.append(j)
			s.add(a[j] - b[j])
	if f:
		if len(s) > 1:
			print('NO')
			continue
		f = True
		for j in range(len(c) - 1):
			if c[j] != c[j + 1] - 1:
				f = False
		if f:
			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 == b:
		print('YES')
	elif a != b:
		c = []
		e = 0
		for i in range(n):
			d = b[i] - a[i]
			c.append(d)
			if d < 0:
				e += 1
			else:
				e += 0
		if e > 0:
			print('NO')
		else:
			g = []
			f = 0
			for i in range(1, n):
				if c[i] == c[i - 1]:
					f += 0
				else:
					f += 1
					g.append(i)
			if f > 2:
				print('NO')
			elif f == 2:
				if c[g[0] - 1] == c[g[0]] == 0 or c[g[0] - 1] == c[g[1]] == 0 or c[g[1] - 1] == c[g[1]] == 0:
					print('YES')
				else:
					print('NO')
			elif f == 1 and c[g[0] - 1] != 0 and (c[g[0]] != 0):
				print('NO')
			else:
				print('YES')


from sys import stdin
for _ in range(int(stdin.readline())):
	l = int(stdin.readline())
	arr1 = list(map(int, stdin.readline().split()))
	arr2 = list(map(int, stdin.readline().split()))
	for i in range(l):
		if arr1[i] != arr2[i]:
			k = arr1[i] - arr2[i]
			if k > 0:
				print('NO')
				break
			b = False
			for j in range(i, l):
				if arr1[j] - arr2[j] != k:
					b = True
					break
			if b:
				for r in range(j, l):
					if arr1[r] != arr2[r]:
						print('NO')
						break
				else:
					print('YES')
			else:
				print('YES')
			break
	else:
		print('YES')


t = int(input())
while t > 0:
	maxVal = 0
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	lo = 0
	hi = n - 1
	while lo < hi and arr2[lo] - arr1[lo] == 0:
		lo += 1
	while lo < hi and arr2[hi] - arr1[hi] == 0:
		hi -= 1
	flag = False
	while lo <= hi:
		diffLo = arr2[lo] - arr1[lo]
		diffHi = arr2[hi] - arr1[hi]
		if diffLo == diffHi and diffLo >= 0 and (diffHi >= 0):
			lo += 1
		else:
			flag = True
			break
	if n == 1:
		if arr2[0] >= arr1[0]:
			print('YES')
		else:
			print('NO')
	elif flag:
		print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	c = []
	n = int(input())
	a = [int(n) for n in input().split()]
	b = [int(n) for n in input().split()]
	f = 0
	for i in range(n):
		c.append(a[i] - b[i])
		if c[i] > 0:
			f = 1
			break
	if f:
		print('NO')
		continue
	ct = 0
	t = c[0]
	if t != 0:
		ct += 1
	for i in c:
		if i != t:
			t = i
			ct += 1
	e = set(c)
	if 0 in e:
		e.remove(0)
	if len(list(set(e))) >= 2 or ct > 2:
		print('NO')
		continue
	print('YES')


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lst = []
	flag = 0
	temp = 0
	k = 0
	m = 0
	for i in range(0, n):
		if a[i] != b[i]:
			if temp == 1:
				k = 1
				break
			else:
				lst.append(b[i] - a[i])
				flag = 1
		elif flag == 1:
			temp = 1
		else:
			m += 1
	if m == n:
		print('YES')
	elif k == 1:
		print('NO')
	elif len(set(lst)) == 1:
		if lst[0] > 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t -= 1


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	k = set()
	d = set()
	for i in range(n):
		if a[i] != b[i]:
			c += 1
			k.add(b[i] - a[i])
			d.add(i)
	f = list(k)
	g = list(d)
	z = 0
	g.sort()
	for i in range(1, len(g)):
		if g[i] != g[i - 1] + 1:
			z = 1
			break
	if len(k) == 0 or (len(d) == c and z == 0 and (len(k) == 1) and (f[0] > 0)):
		print('YES')
	else:
		print('NO')


all = int(input())
for kk in range(all):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	l = -1
	r = -1
	k = 0
	delta = 0
	answer = 'YES'
	for i in range(len(a)):
		delta = b[i] - a[i]
		if delta != 0:
			if l == -1:
				k = delta
				l = i
			if l != -1 and delta != k:
				answer = 'NO'
			if r != -1:
				answer = 'NO'
		if delta == 0 and l != -1 and (r == -1):
			r = i
	if k < 0:
		answer = 'NO'
	print(answer)


def push(a, b):
	n = len(a)
	diff = []
	for i in range(n):
		c = b[i] - a[i]
		diff.append(c)
	m = min(diff)
	if m < 0:
		return 'NO'
	t = 0
	for j in range(n):
		if diff[j] != 0:
			for k in range(j + 1, n):
				if diff[k] == 0:
					t = k
					break
				if diff[k] != diff[j]:
					return 'NO'
			if t == 0:
				return 'YES'
			break
	for h in range(t, n):
		if diff[h] != 0:
			return 'NO'
	return 'YES'
T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(push(a, b))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	l = [b[i] - a[i] for i in range(n)]
	min = -1
	max = -1
	for i in range(n):
		if l[i] != 0:
			min = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] != 0:
			max = i
			break
	if min == max == -1:
		print('YES')
	elif max == -1 or min == -1:
		print('NO')
	elif l[min] < 0:
		print('NO')
	else:
		for i in range(min, max + 1, 1):
			if l[i] != l[min]:
				print('NO')
				break
		else:
			print('YES')


for u in range(int(input())):
	n = int(input())
	x = [int(w) for w in input().split()]
	y = [int(w) for w in input().split()]
	z = []
	t = True
	for i in range(n):
		if y[i] - x[i] < 0:
			t = False
			break
		else:
			z.append(y[i] - x[i])
	if t == False:
		print('NO')
	else:
		a = 0
		for i in range(n):
			if z[i] > 0:
				a = i
				break
		b = 0
		r = z[::-1]
		for i in range(n):
			if r[i] > 0:
				b = i
				break
		b = n - i - 1
		f = True
		for i in range(a, b):
			if z[i] != z[i + 1]:
				f = False
				break
		if f:
			print('YES')
		else:
			print('NO')


q = int(input())
l = []
for i in range(q):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	test = 0
	s = 0
	for j in range(n):
		if x[j] != y[j]:
			s = x[j] - y[j]
			k = j
			break
	if s > 0:
		print('NO')
	elif s == 0:
		print('YES')
	elif n == 1:
		print('YES')
	else:
		g = -1
		for h in range(k, n):
			if x[h] - y[h] != s:
				g = h
				break
		if g == -1:
			print('YES')
		else:
			for d in range(g, n):
				if x[d] - y[d] != 0:
					test = 1
					break
			if test == 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()))
	c = []
	for i in range(n):
		c.append(b[i] - a[i])
	c.append(0)
	c.insert(0, 0)
	ct = 0
	(k, l) = (0, 0)
	for i in range(len(c) - 1):
		if c[i + 1] != c[i]:
			ct += 1
			k = c[i]
			l = c[i + 1]
	j = 1
	if k < 0 or l < 0:
		j = 0
	if ct <= 2 and j:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	p = [bi - ai for (ai, bi) in zip(a, b)]
	i = 0
	while i < n and p[i] == 0:
		i += 1
	j = i
	while i < n and p[j] > 0 and (p[i] == p[j]):
		i += 1
	while i < n and p[i] == 0:
		i += 1
	if i == n:
		print('YES')
	else:
		print('NO')


t = int(input())
for I in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	arr = []
	poss = 1
	for i in range(n):
		if b[i] - a[i] < 0:
			poss = 0
			break
		if b[i] - a[i] > 0:
			arr.append([b[i] - a[i], i])
	if poss == 0:
		print('NO')
	else:
		s = set()
		for i in arr:
			s.add(i[0])
		if len(s) > 1:
			poss = 0
		if poss:
			for i in range(len(arr) - 1):
				if abs(arr[i][1] - arr[i + 1][1]) > 1:
					poss = 0
					break
		if poss:
			print('YES')
		else:
			print('NO')


def same(a, b):
	foo = 1
	for i in range(len(a)):
		if a[i] != b[i]:
			return 0
	return 1

def perfect(a, b):
	foo = 1
	for i in range(len(a)):
		if a[i] > b[i]:
			return 0
	return 1
for _ in range(int(input())):
	n = int(input())
	aray = list(map(int, input().split()))
	bray = list(map(int, input().split()))
	if same(aray, bray):
		print('YES')
		continue
	if perfect(aray, bray) == 0:
		print('NO')
		continue
	this = [aray[i] - bray[i] for i in range(n)]
	for i in range(n):
		if this[i] != 0:
			ans = i
			break
	if ans == n - 1:
		print('YES')
		continue
	array = this[ans:]
	while 1:
		if array[-1] == 0:
			array.pop()
		else:
			break
	k = array[0]
	foo = 1
	for i in array:
		if i != k:
			foo = 0
			break
	if foo == 1:
		print('YES')
	else:
		print('NO')


queries = int(input())
for x in range(queries):
	n = int(input())
	a = input().split()
	b = input().split()
	differences = []
	indices = []
	flag = True
	for x in range(len(a)):
		if a[x] != b[x]:
			differences.append(int(b[x]) - int(a[x]))
			indices.append(x)
	length = len(differences)
	differences = set(differences)
	for x in differences:
		if x < 0:
			flag = False
	if len(differences) == 1:
		for x in range(len(indices) - 1):
			if indices[x] != indices[x + 1] - 1:
				flag = False
	if len(differences) > 1 or flag == False:
		print('NO')
	else:
		print('YES')


import sys
for T in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	i = 0
	s = 0
	f = True
	while i < n:
		if a[i] != b[i]:
			s = b[i] - a[i]
			break
		i += 1
	if s < 0:
		f = False
	while i < n and a[i] != b[i]:
		if b[i] - a[i] != s:
			f = False
		i += 1
	while i < n:
		if a[i] != b[i]:
			f = False
		i += 1
	print('YES' if f else 'NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(__) for __ in input().split()]
	b = [int(___) for ___ in input().split()]
	for i in range(n):
		b[i] -= a[i]
	x = 0
	y = n - 1
	while x < n:
		if b[x] != 0:
			break
		x += 1
	while y >= 0:
		if b[y] != 0:
			break
		y -= 1
	if len(set(b[x:y + 1])) == 1 and b[x:y + 1][0] > 0 or len(set(b[x:y + 1])) == 0:
		print('YES')
	else:
		print('NO')


def calc(up, down):
	curr_diff = 1
	prev_zero_found = False
	for i in range(len(up)):
		diff = up[i] - down[i]
		if diff == 0:
			if curr_diff == 1:
				continue
			else:
				prev_zero_found = True
		elif diff > 0:
			print('NO')
			return
		elif curr_diff == 1:
			curr_diff = diff
		elif curr_diff != diff:
			print('NO')
			return
		elif prev_zero_found:
			print('NO')
			return
	print('YES')
	return
t = int(input())
for i in range(t):
	n = int(input())
	first_arr = input().split()
	second_arr = input().split()
	up = list()
	down = list()
	for a in first_arr:
		up.append(int(a))
	for b in second_arr:
		down.append(int(b))
	calc(up, down)


from itertools import groupby
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	for (a, b) in zip(A, B):
		C.append(b - a)
	D = []
	for (v, g) in groupby(C):
		D.append(v)
	if len(D) == 1:
		if D[0] >= 0:
			print('YES')
		else:
			print('NO')
	elif len(D) == 2:
		if 0 in D:
			D.remove(0)
			if D[0] >= 0:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif len(D) == 3:
		if D[0] == D[-1] == 0 and D[1] >= 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


T = int(input())
for t in range(T):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = 'YES'
	c = 0
	d = 0
	t = 0
	for (ia, ib) in zip(a, b):
		t = ib - ia
		if t < 0:
			r = 'NO'
			break
		if d:
			if t and t - d:
				r = 'NO'
				break
		elif t:
			if c:
				r = 'NO'
				break
			c += 1
		d = t
	print(r)


def singlepush(a, b, n):
	r = []
	d = []
	if sum(a) > sum(b):
		print('NO')
	else:
		for i in range(len(a)):
			r.append(b[i] - a[i])
			if b[i] - a[i] != 0:
				d.append(i)
		if d != []:
			if len(set(r[d[0]:d[-1] + 1])) == 1 or len(r) == 1:
				print('YES')
			else:
				print('NO')
		else:
			print('YES')
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	singlepush(a, b, n)


from itertools import groupby as g
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [y - x for (x, y) in zip(a, b)]
	if min(l) < 0:
		print('NO')
		continue
	temp = g(l)
	te = [len(tuple(v)) for (k, v) in temp if k > 0]
	if len(te) > 1:
		print('NO')
	else:
		print('YES')


import sys, math
input = sys.stdin.readline

def inp():
	n = int(input())
	return n

def inlt():
	a = list(map(int, input().split()))
	return a

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

def invr():
	(a, b, c) = map(int, input().split())
	return (a, b, c)
t = 1
t = inp()
for i in range(t):
	n = inp()
	a = inlt()
	b = inlt()
	q = []
	for j in range(len(a)):
		q.append(b[j] - a[j])
	i = 0
	while i < n and q[i] == 0:
		i = i + 1
	j = i
	while j < n and q[j] == q[i]:
		j = j + 1
	k = j
	while k < n and q[k] == 0:
		k = k + 1
	if i == n or (q[i] > 0 and k == n):
		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 == b:
		print('YES')
		continue
	flag = 0
	for i in range(n):
		if a[i] > b[i]:
			flag = 1
			break
	if flag == 1:
		print('NO')
		continue
	ind = []
	diff = None
	for i in range(n):
		if a[i] != b[i]:
			diff = b[i] - a[i]
			break
	flag = 0
	for i in range(n):
		if a[i] != b[i] and b[i] - a[i] == diff:
			ind += [i]
		elif a[i] != b[i] and b[i] - a[i] != diff:
			flag = 1
			break
	if flag == 1:
		print('NO')
		continue
	flag = 0
	for j in range(1, len(ind)):
		if ind[j] - ind[j - 1] != 1:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


i = lambda : map(int, input().split())
for _ in [0] * int(input()):
	input()
	b = []
	for (x, y) in zip(i(), i()):
		b += [x - y]
	k = 0
	l = len(b)
	while k < l and b[k] == 0:
		k += 1
	while l > 0 and b[l - 1] == 0:
		l -= 1
	print('YNEOS'[any((x > 0 or x != b[k] for x in b[k:l]))::2])


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


import math
import os
import random
import re
import sys

def check(arr1, arr2):
	i = 0
	k = 0
	while i < len(arr1):
		if arr1[i] == arr2[i]:
			pass
		elif arr2[i] - arr1[i] < 0:
			return False
		elif k == 0:
			k = arr2[i] - arr1[i]
			lastIndex = i
		elif arr1[i] + k == arr2[i] and i == lastIndex + 1:
			lastIndex = i
		else:
			return False
		i += 1
	return True
t = int(input())
while t > 0:
	n = int(input())
	arr1 = list(map(int, input().rstrip().split()))
	arr2 = list(map(int, input().rstrip().split()))
	result = check(arr1, arr2)
	if result:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	f = 0
	xf = 0
	d = n
	for i in range(n):
		if f == 0 and l[i] != lb[i]:
			f = 1
			x = lb[i] - l[i]
			if x < 0:
				xf = 1
				break
		elif f == 1 and l[i] != lb[i]:
			if lb[i] - l[i] == x:
				continue
			else:
				xf = 1
				break
		elif f == 1 and lb[i] == l[i]:
			f = 2
		elif f == 2 and lb[i] != l[i]:
			xf = 1
			break
	if xf == 0:
		ans = 'YES'
	else:
		ans = 'NO'
	print(ans)


n = int(input())

def check():
	k = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l_i = []
	p = 0
	for i in range(k):
		raz = l2[i] - l1[i]
		if raz >= 0:
			l_i.append(raz)
		else:
			p = 'NO'
			print(p)
			break
	if p == 0:
		if len(set(l_i)) <= 2:
			l_r = [l_i[0]]
			for j in range(1, len(l_i)):
				if l_i[j] != l_r[len(l_r) - 1]:
					l_r.append(l_i[j])
			if sum(l_r) == 0:
				print('YES')
			elif 0 in l_r and len(set(l_r)) == 2:
				for w in l_r:
					if w != 0:
						if l_r.count(w) == 1:
							print('YES')
							break
						else:
							print('NO')
							break
			elif 0 not in l_r and len(set(l_r)) == 1:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
for s in range(n):
	check()


def main():
	T = False
	b = int(input())
	c1 = list(map(int, input().split()))
	c2 = list(map(int, input().split()))
	if c1 == c2:
		print('YES')
		return 0
	if b == 1:
		if c1[0] - c2[0] <= 0:
			print('YES')
		else:
			print('NO')
		return 0
	k = 0
	S = False
	for i in range(len(c1)):
		if T:
			print('NO')
			return 0
		if c1[i] != c2[i] and k != 0 and (not S):
			if c1[i] - c2[i] != k:
				T = True
		if c1[i] == c2[i] and k != 0:
			S = True
		if c1[i] != c2[i] and k != 0 and S:
			T = True
		if c1[i] != c2[i] and k == 0:
			k = c1[i] - c2[i]
		if k > 0:
			T = True
		if T:
			print('NO')
			return 0
	print('YES')
	return 0
a = int(input())
for i in range(a):
	main()


for _ in range(int(input())):
	(n, flag) = (int(input()), 0)
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	k = -1
	for i in range(n):
		if l1[i] != l2[i]:
			if k == -1:
				k = l2[i] - l1[i]
			l1[i] += abs(k)
		elif k == -1:
			continue
		else:
			break
	print(['NO', 'YES'][l1 == l2])


for i in range(int(input())):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	diff = []
	an = 0
	for j in range(n):
		diff.append(ar1[j] - ar2[j])
		if ar1[j] - ar2[j] > 0:
			an = 1
	s = ''
	diff.append(0)
	se = list(set(diff))
	if len(se) > 2 or an == 1:
		print('NO')
	else:
		for j in range(n):
			if j == 0:
				if diff[j] == 0:
					s += '0'
				else:
					s += '1'
			elif diff[j] == 0:
				if s[-1] == '1':
					s += '0'
			elif s[-1] == '0':
				s += '1'
		if '101' in s:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().strip().split()]
	B = [int(x) for x in input().strip().split()]
	D = [B[i] - A[i] for i in range(N)]
	S = False
	Z = False
	v = 0
	for (i, val) in enumerate(D):
		if S and val == 0:
			Z = True
		elif S and val != 0 and (val != v) or (Z and val != 0):
			print('NO')
			break
		elif val != 0 and (not S):
			v = val
			if val < 0:
				print('NO')
				break
			S = True
	else:
		print('YES')


n = int(input())
for i in range(n):
	length = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	k = 0
	no = False
	for j in range(length):
		if a[j] != b[j] and k == 0:
			k = b[j] - a[j]
			if k < 0:
				no = True
				break
		elif b[j] - a[j] != k and a[j] != b[j]:
			no = True
			break
		if a[j] == b[j] and k > 0:
			k = -1
		elif a[j] != b[j] and k == -1:
			no = True
			break
	print('NO' if no else 'YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = -1
	diff_temp = -1
	flag1 = False
	flag = True
	for i in range(n):
		if a[i] <= b[i]:
			if a[i] != b[i]:
				diff_temp = b[i] - a[i]
				if diff < 0:
					diff = diff_temp
				elif diff_temp != diff:
					print('NO')
					flag = False
					break
				elif flag1:
					print('NO')
					flag = False
					break
			else:
				if diff > 0:
					flag1 = True
				continue
		else:
			print('NO')
			flag = False
			break
	if flag:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	list1 = input().split()
	list2 = input().split()
	l = len(list1)
	list5 = []
	for j in range(l):
		list5.append(int(list2[j]) - int(list1[j]))
	f = 0
	list6 = []
	for j in list5:
		if j < 0:
			f = 1
			break
		if j not in list6:
			list6.append(j)
	l1 = len(list6)
	x = 0
	for j in range(l):
		if list5[j] != 0:
			x = j
			break
	count = 0
	y = 0
	if l1 > 1:
		y = list5.count(list5[x])
		z = x
		for j in list5:
			if z < l:
				if list5[z] != 0:
					count += 1
					z += 1
	if f == 0 and l1 <= 2 and (count == y):
		print('YES')
	else:
		print('NO')


t = int(input())

def check():
	l = int(input())
	diff = 0
	a = map(int, input().split())
	b = map(int, input().split())
	for (a1, b1) in zip(a, b):
		if b1 - a1 < 0:
			return 'NO'
		elif b1 - a1 != 0:
			if diff != 0 and b1 - a1 != diff:
				return 'NO'
			diff = b1 - a1
		elif a1 == b1 and diff != 0:
			diff = -1
	return 'YES'
for _ in range(t):
	print(check())


def main():

	def solve():
		n = int(input())
		aa = [int(a) for a in input().split()]
		bb = [int(a) for a in input().split()]
		l_found = False
		r_found = False
		for (a, b) in zip(aa, bb):
			if a == b:
				if l_found:
					r_found = True
			else:
				if r_found:
					print('NO')
					return
				if l_found:
					if b - a != k:
						print('NO')
						return
				l_found = True
				k = b - a
				if k < 0:
					print('NO')
					return
		print('YES')
	q = int(input())
	for _ in range(q):
		solve()
main()


def myfunc(a, b, n):
	l = [b[i] - a[i] for i in range(n)]
	x = 0
	y = 0
	temp = 0
	if a == b:
		return 'YES'
	if n == 1 and l[0] < 0:
		return 'NO'
	else:
		for i in range(n):
			if l[i] < 0:
				return 'NO'
				break
			elif l[i] > 0:
				x = i
				break
			else:
				continue
		for j in range(n - 1, -1, -1):
			if l[j] < 0:
				return 'NO'
				break
			elif l[j] > 0:
				y = j
				break
		temp = l[x]
		for i in range(x, y + 1):
			if l[i] < 0:
				return 'NO'
				break
			elif l[i] == temp and i != y:
				continue
			elif l[i] == temp and i == y:
				return 'YES'
				break
			else:
				return 'NO'
				break
t = int(input(''))
for i in range(t):
	n = int(input(''))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(myfunc(a, b, n))


from sys import stdin
r = stdin.readline

def solve(a1, a2):
	(state, dif) = (0, float('inf'))
	for i in range(len(a1)):
		if a1[i] > a2[i]:
			return False
		elif a1[i] < a2[i] and state == 0:
			(state, dif) = (1, a1[i] - a2[i])
		elif a1[i] < a2[i] and state == 1 and (a1[i] - a2[i] != dif):
			return False
		elif a1[i] == a2[i] and state == 1:
			state = 2
		elif a1[i] < a2[i] and state == 2:
			return False
	return True

def main():
	cases = int(r())
	for case in range(cases):
		n = int(r())
		a1 = list(map(int, r().strip().split()))
		a2 = list(map(int, r().strip().split()))
		print('YES' if solve(a1, a2) else 'NO')
main()


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	s = 0
	e = 0
	for i in range(n):
		if a[i] != b[i]:
			s = i
			break
	diff = b[s] - a[s]
	for j in range(s + 1, n):
		if a[j] == b[j]:
			e = j
			break
	if e == 0:
		e = n
	if diff < 0:
		diff = 0
	for i in range(s, e):
		a[i] += diff
	print('YNEOS'[not a == b::2])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		b = LI()
		r = True
		t = 0
		c = 0
		for (d, e) in zip(a, b):
			if e < d:
				r = False
				break
			k = e - d
			if k != c and k != 0:
				t += 1
			c = k
		rr.append(YES(r and t < 2))
	return JA(rr, '\n')
print(main())


N = int(input())
for i in range(N):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	else:
		ar = []
		for j in range(n):
			if a[j] != b[j]:
				ar.append(j)
		l = min(ar)
		r = max(ar)
		if b[l] - a[l] >= 0:
			k = b[l] - a[l]
			for m in range(l, r + 1):
				a[m] = a[m] + k
			if a == b:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	inf = float('inf')
	diff = inf
	flag = 0
	done = 0
	for i in range(n):
		d = a[i] - b[i]
		if d > 0:
			flag = 1
			break
		if d:
			if done:
				flag = 1
				break
			if diff == inf:
				diff = d
			if diff != d:
				flag = 1
				break
		elif diff != inf:
			done = 1
	if flag:
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if sum(a) > sum(b):
		print('NO')
	else:
		k = -1
		for i in range(m):
			if a[i] == b[i]:
				if k == -1:
					continue
				else:
					break
			else:
				if k == -1:
					k = b[i] - a[i]
				a[i] += abs(k)
		if a == b:
			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()]
	temp = 0
	diff = []
	for i in range(n):
		if a[i] != b[i] and (temp == 0 or temp == 1):
			temp = 1
			diff.append(b[i] - a[i])
		elif a[i] == b[i] and temp == 1:
			temp = 2
		elif a[i] != b[i] and temp == 2:
			temp = 3
	if temp == 3:
		print('NO')
	elif temp == 0:
		print('YES')
	elif temp == 1 or temp == 2:
		if diff.count(diff[0]) == len(diff) and diff[0] > 0:
			print('YES')
		else:
			print('NO')


def comp(a, b):
	n = len(a)
	c = []
	i = 0
	while i < n and a[i] == b[i]:
		i += 1
	if i == n:
		print('YES')
		return
	k = b[i] - a[i]
	if k <= 0:
		print('NO')
		return
	while i < n and a[i] + k == b[i]:
		i += 1
	if i == n:
		print('YES')
		return
	while i < n and a[i] == b[i]:
		i += 1
	if i == n:
		print('YES')
		return
	print('NO')
	return
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	comp(a, b)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	dr = []
	c = []
	for j in range(n):
		dr.append(b[j] - a[j])
		if dr[-1] not in c:
			c.append(dr[-1])
	if len(c) > 2:
		print('NO')
	elif len(c) == 1:
		if c[0] < 0:
			print('NO')
		else:
			print('YES')
	elif 0 not in c:
		print('NO')
	elif c[0] == 0 and c[1] >= 0:
		first = dr.index(c[1])
		last = dr[::-1].index(c[1])
		if 0 in dr[first + 1:n - 1 - last]:
			print('NO')
		else:
			print('YES')
	elif c[1] == 0 and c[0] >= 0:
		first = dr.index(c[0])
		last = dr[::-1].index(c[0])
		if 0 in dr[first + 1:n - 1 - last]:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	a = [int(j) for j in input().strip().split()]
	b = [int(j) for j in input().strip().split()]
	delta = []
	for k in range(n):
		delta.append(b[k] - a[k])
	dset = set(delta)
	if min(dset) < 0:
		print('NO')
	elif len(dset) > 2:
		print('NO')
	elif len(dset) == 2 and 0 not in dset:
		print('NO')
	else:
		flag = 0
		x0 = delta[0]
		for d in range(1, n):
			if delta[d] != x0:
				flag += 1
			x0 = delta[d]
		if flag > 2:
			print('NO')
		elif flag < 2:
			print('YES')
		elif delta[0] == 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()))
	t = []
	val = 0
	dif = -1
	for i in range(len(B)):
		if B[i] != A[i] and A[i] < B[i] and (dif == -1 or B[i] - A[i] == dif):
			t.append(i)
			dif = B[i] - A[i]
		elif B[i] != A[i] and (A[i] > B[i] or B[i] - A[i] != dif):
			print('NO')
			val = 1
			break
	if val == 0:
		if len(t) == 1 or len(t) == 0:
			print('YES')
		else:
			var = 0
			for i in range(1, len(t)):
				if t[i] - t[i - 1] > 1:
					print('NO')
					var = 1
					break
			if var == 0:
				print('YES')


def Push(a, b, n):
	l = 0
	r = 0
	if a == b:
		return 'YES'
	for j in range(n):
		if a[j] == b[j]:
			l += 1
		if int(a[j]) != int(b[j]):
			break
	for s in range(n):
		if int(a[s]) != int(b[s]):
			r += 1
	k = abs(b[l] - a[l])
	for index in range(l, l + r):
		a[index] = a[index] + k
	if a == b:
		return 'YES'
	else:
		return 'NO'
key = int(input())
for i in range(key):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	print(Push(arr1, arr2, n))


def solve(a, b, n, l=0, r=0, k=0):
	while l < n:
		if b[l] - a[l] == 0:
			l += 1
			r += 1
		else:
			r = l
			k = b[l] - a[l]
			break
	if k < 0:
		return 'NO'
	while r < n:
		if b[r] - a[r] == k:
			r += 1
		else:
			break
	j = r
	while j < n:
		if b[j] - a[j] != 0:
			return 'NO'
		j += 1
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = r = 0
	k = 0
	print(solve(a, b, n))


def solve():
	n = int(input())
	a = [0] * (n + 2)
	b = [0] * (n + 2)
	diff = [0] * (n + 2)
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	for i in range(n):
		a[i + 1] = x[i]
	for i in range(n):
		b[i + 1] = y[i]
	for i in range(1, n + 1):
		diff[i] = b[i] - a[i]
	cnt = 0
	for i in range(0, n + 1):
		if diff[i] < 0:
			return False
		if diff[i] != diff[i + 1]:
			cnt += 1
	return cnt <= 2
for _ in range(int(input())):
	if solve() == True:
		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()))
	r = [b[i] - a[i] for i in range(n)]
	if any((value < 0 for value in r)):
		print('NO')
	else:
		consecutive = False
		k = 0
		for value in r:
			if value > 0 and (not consecutive) and (not k):
				k = value
				consecutive = True
			elif value > 0 and k and (value != k):
				print('NO')
				break
			elif value > 0 and (not consecutive):
				print('NO')
				break
			elif value == 0:
				consecutive = False
		else:
			print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = [0] * n
	result = True
	for i in range(n):
		diff[i] = b[i] - a[i]
		if diff[i] < 0 or (i > 0 and diff[i] != diff[i - 1] and (diff[i - 1] != 0) and (diff[i] != 0)):
			result = False
			break
	has_zero = False
	has_nonzero = False
	for i in range(n):
		if diff[i] > 0 and (not has_nonzero) and (not has_zero):
			has_nonzero = True
		elif diff[i] == 0 and has_nonzero and (not has_zero):
			has_zero = True
		elif diff[i] > 0 and has_zero and has_nonzero:
			result = False
	print('YES' if result else 'NO')


for _ in range(int(input())):
	number = int(input())
	work = list(map(int, input().split()))
	result = list(map(int, input().split()))
	if work == result:
		print('YES')
		continue
	i = 0
	while work[i] == result[i]:
		i += 1
	l = i
	while i < number:
		if work[i] != result[i]:
			r = i
		i += 1
	k = result[l] - work[l]
	if k < 0:
		print('NO')
		continue
	go = True
	while l < r + 1:
		work[l] = work[l] + k
		if work[l] != result[l]:
			print('NO')
			go = False
			break
		l += 1
	if go:
		print('YES')


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input()
t = I()
for i in range(0, t):
	n = I()
	a = li()
	b = li()
	s = []
	flag = 0
	k = 0
	c = []
	for i in range(0, n):
		if a[i] != b[i]:
			if a[i] > b[i]:
				flag = 1
				break
			elif k == 0:
				s.append(b[i] - a[i])
				c.append(i)
				k = 1
			elif b[i] - a[i] != s[0]:
				flag = 1
				break
			elif c[-1] != i - 1:
				flag = 1
				break
			else:
				c.append(i)
	if flag == 0:
		print('YES')
	else:
		print('NO')


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


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	b = array()
	dif = set()
	ind = []
	f = 1
	for i in range(n):
		d = b[i] - a[i]
		if d < 0:
			f = 0
			break
		elif d > 0:
			dif.add(d)
			ind.append(i)
	if f == 0 or len(dif) > 1:
		print('NO')
		continue
	f = 1
	for i in range(1, len(ind)):
		if ind[i] - ind[i - 1] != 1:
			f = 0
			print('NO')
			break
	if f:
		print('YES')


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


for _ in range(int(input())):
	n = int(input())
	LISTT = [*map(int, input().split())]
	LISTT2 = [*map(int, input().split())]
	Booleann = False
	k = 0
	Sett = set()
	i = 0
	Booleann1 = True
	XXZ = []
	Sett = set()
	while i < n:
		Sett.add(LISTT[i] - LISTT2[i])
		if LISTT[i] != LISTT2[i] and k == 0:
			k = LISTT[i] - LISTT2[i]
			if k > 0:
				Booleann1 = False
				break
			XXZ.append(i)
			i += 1
			continue
			Booleann = True
		if Booleann1 and LISTT[i] != LISTT2[i] and (LISTT[i] - LISTT2[i] != k):
			Booleann1 = False
			break
		if Booleann1 and LISTT[i] != LISTT2[i] and (LISTT[i] - LISTT2[i] == k):
			XXZ.append(i)
			if XXZ[-1] - XXZ[-2] != 1:
				Booleann1 = False
				break
		i += 1
	if Booleann1 and len(Sett) <= 2:
		print('YES')
	else:
		print('NO')


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	b = li()
	i = 0
	j = n - 1
	while i < n and a[i] == b[i]:
		i += 1
	while j >= 0 and a[j] == b[j]:
		j -= 1
	if i < n and j >= 0:
		d = b[i] - a[i]
		if d < 0 or any((b[k] - a[k] != d for k in range(i, j + 1))):
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


def main():
	l = []
	for i in range(int(input())):
		n = int(input())
		ina = input().split()
		inb = input().split()
		c = [int(inb[i]) - int(ina[i]) for i in range(n)]
		f = True
		for i in c:
			if i < 0:
				f = False
				break
		if not f:
			l.append('NO')
		else:
			c = [0] + c + [0]
			s = 0
			for i in range(len(c) - 1):
				if c[i] != c[i + 1]:
					s += 1
			if s > 2:
				l.append('NO')
			else:
				l.append('YES')
	for i in l:
		print(i)
main()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	while l < n:
		if a[l] != b[l]:
			break
		l += 1
	while r >= 0:
		if a[r] != b[r]:
			break
		r -= 1
	if l == n:
		return 'YES'
	add = b[l] - a[l]
	if add < 0:
		return 'NO'
	for i in range(l, r + 1):
		a[i] += add
	return 'YES' if a == b else 'NO'

def main():
	t = int(input())
	for _ in range(t):
		print(solve())
main()


q = int(input())
for qq in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	started = False
	ended = False
	possible = True
	diff = 0
	for i in range(n):
		if a[i] != b[i]:
			if a[i] > b[i]:
				possible = False
				break
			elif ended:
				possible = False
				break
			elif started and b[i] - a[i] != diff:
				possible = False
				break
			elif started:
				continue
			elif not started:
				started = True
				diff = b[i] - a[i]
		elif a[i] == b[i] and started:
			ended = True
	if possible:
		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()))
	state = 1
	good = True
	for i in range(n):
		if state == 1:
			if a[i] != b[i]:
				state = 2
				diff = b[i] - a[i]
				if diff < 0:
					good = False
					break
		elif state == 2:
			if a[i] != b[i]:
				diff2 = b[i] - a[i]
				if diff2 != diff:
					good = False
					break
			else:
				state = 3
		elif state == 3:
			if a[i] != b[i]:
				good = False
				break
	if not good:
		print('NO')
	else:
		print('YES')


amI = int(input())
for i in range(amI):
	am = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = 0
	flag1 = False
	flag2 = False
	ans = 'YES'
	for g in range(am):
		if not a[g] == b[g]:
			if not isinstance(flag1, bool) and (not isinstance(flag2, bool)):
				ans = 'NO'
				break
			elif not isinstance(flag1, bool):
				if not b[g] - a[g] == diff:
					ans = 'NO'
					break
			else:
				diff = b[g] - a[g]
				if diff <= 0:
					ans = 'NO'
					break
				if isinstance(flag1, bool):
					flag1 = g
				elif isinstance(flag1, bool) and (not isinstance(flag2, bool)):
					ans = 'NO'
					break
				else:
					print(flag1)
		elif not isinstance(flag1, bool):
			flag2 = g
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	k = -99999
	for i in range(n):
		if a[i] != b[i]:
			if k == -99999:
				k = b[i] - a[i]
			a[i] += abs(k)
		elif k == -99999:
			continue
		else:
			break
	if 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()))
	k = None
	l = None
	r = None
	for i in range(n):
		if b[i] - a[i] < 0:
			print('NO')
			break
		elif b[i] - a[i] > 0 and k == None:
			k = b[i] - a[i]
			l = i
		elif b[i] - a[i] > 0:
			if b[i] - a[i] != k:
				print('NO')
				break
			elif i != r and r != None:
				print('NO')
				break
		elif b[i] == a[i] and k != None:
			r = i
		if i == n - 1:
			print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pd = b[0] - a[0]
	if pd < 0:
		print('NO')
		continue
	f = True
	f1 = True
	for i in range(1, n):
		d = b[i] - a[i]
		if d < 0 or (d != pd and pd != 0 and (d != 0)):
			print('NO')
			break
		if d != pd and d == 0:
			if f1:
				f1 = False
				f = False
			else:
				print('NO')
				break
		elif d != pd and pd == 0:
			if f:
				f = False
			else:
				print('NO')
				break
		pd = d
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	k = 0
	yes = True
	first = True
	l = r = -1
	for i in range(n):
		a = arr[i]
		b = arr2[i]
		if b - a > 0:
			if l < 0:
				l = i
				k = b - a
			if b - a != k or r >= 0:
				yes = False
				break
		elif b - a == 0 and l >= 0:
			r = i
		elif b - a != 0:
			yes = False
			break
	print('YES' if yes else 'NO')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [b[i] - a[i] for i in range(n)]
	d = []
	flag = 1
	for i in range(n - 1):
		if l[i] < 0:
			flag = 0
			break
		if l[i] != l[i + 1]:
			p = 1
			d.append(l[i])
	if l[-1] < 0:
		flag = 0
	d.append(l[-1])
	if flag == 0 or len(d) > 3:
		print('NO')
	elif len(d) == 3:
		if d[0] == 0 and d[-1] == 0:
			print('YES')
		else:
			print('NO')
	elif len(d) == 2:
		if d[0] == 0 or d[1] == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


t = int(input())
from math import *
while t > 0:
	t -= 1
	n = int(input())
	flag = 0
	f = 0
	ss = 0
	zz = -9999999999999
	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]:
			ss = 1
			break
		if a[i] != b[i] and zz == -9999999999999:
			zz = a[i] - b[i]
			flag = 1
			f = 1
		elif a[i] != b[i] and zz != a[i] - b[i]:
			flag = 1
			ss = 1
			break
		elif a[i] != b[i] and flag == 0 and (f == 1):
			ss = 1
			break
		elif a[i] == b[i]:
			flag = 0
	print('YES' if not ss else 'NO')


q = int(input())
ans = []
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	was = False
	prev = 0
	c = []
	for i in range(n):
		c.append(b[i] - a[i])
	counter = 0
	prev = None
	right = []
	for el in c:
		if el != prev:
			right.append(el)
		prev = el
	counter = 0
	ok = True
	for i in right:
		if i < 0:
			ok = False
		elif i > 0:
			counter += 1
	if ok and counter <= 1:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	C = [b - a for (a, b) in zip(A, B)]
	while C and C[-1] == 0:
		C.pop()
	C.reverse()
	while C and C[-1] == 0:
		C.pop()
	if not C or (len(set(C)) == 1 and C[0] > 0):
		Ans[qu] = 'YES'
	else:
		Ans[qu] = 'NO'
print('\n'.join(map(str, Ans)))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:n]
	c = []
	d = []
	e = 0
	for j in range(len(a)):
		if a[j] > b[j]:
			e = 1
			break
		if a[j] != b[j]:
			if len(d) == 0:
				d.append(a[j] - b[j])
			elif d[-1] != a[j] - b[j]:
				c.append(d)
				d = []
				d.append(a[j] - b[j])
		elif len(d) > 0 and a[j] == b[j]:
			c.append(d)
			d = []
	if len(d) > 0:
		c.append(d)
	if e == 1:
		print('NO')
	elif len(c) <= 1:
		print('YES')
	else:
		print('NO')


from os import path
import sys
from math import ceil, floor, gcd, log
from collections import defaultdict, Counter
maxx = float('inf')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
else:
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
for _ in range(I()):
	n = I()
	a = lint()
	b = lint()
	if n == 1:
		if a[0] <= b[0]:
			print('YES')
		else:
			print('NO')
		continue
	f = True
	cnt = []
	s = set()
	for i in range(n):
		if b[i] - a[i] > 0:
			cnt.append(i)
			s.add(b[i] - a[i])
		elif b[i] - a[i] < 0:
			f = False
			break
	if f:
		for j in range(len(cnt) - 1):
			if cnt[j + 1] - cnt[j] != 1:
				f = False
				break
	if f and len(s) <= 1:
		print('YES')
	else:
		print('NO')


import sys

def elevate(a, b, n):
	used = False
	k = -1
	prev = b[0] - a[0]
	if prev < 0:
		return False
	elif prev > 0:
		k = prev
	for i in range(1, n):
		d = b[i] - a[i]
		if d < 0:
			return False
		elif d == 0:
			if prev > 0:
				used = True
		elif d > 0:
			if k < 0:
				k = d
			elif d != k:
				return False
			elif used:
				return False
	return True
reader = (map(int, s.split()) for s in sys.stdin)
(t,) = next(reader)
for _ in range(t):
	(n,) = next(reader)
	a = list(next(reader))
	b = list(next(reader))
	print('YES' if elevate(a, b, n) else 'NO')


import sys

class ASinglePush:

	def solve(self):
		t = int(input())
		for _ in range(t):
			n = int(input())
			a = [int(_) for _ in input().split()]
			b = [int(_) for _ in input().split()]
			u = [b[i] - a[i] for i in range(n)]
			l = -1
			r = -1
			for i in range(n):
				if u[i]:
					l = i
					break
			for i in range(n - 1, -1, -1):
				if u[i]:
					r = i
					break
			if l == -1:
				print('YES')
			else:
				assert l != -1 and r != -1
				print('YES' if u[l] > 0 and u[l:r + 1] == [u[l]] * (r - l + 1) else 'NO')
solver = ASinglePush()
input = sys.stdin.readline
solver.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]:
			k = b[i] - a[i]
			if k > 0:
				for i in range(i, n):
					if a[i] == b[i]:
						break
					else:
						b[i] -= k
				break
	if a == b:
		print('YES')
	else:
		print('NO')


def allsame(c):
	if not c:
		return 'YES'
	if c[0] < 0:
		return 'NO'
	for i in range(1, len(c)):
		if c[i] != c[0]:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [b[i] - a[i] for i in range(n)]
	while c and c[0] == 0:
		c.pop(0)
	while c and c[-1] == 0:
		c.pop(-1)
	print(allsame(c))


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	n = int(ip())
	a = list(map(int, ip().split()))
	b = list(map(int, ip().split()))
	(l, r) = (0, n - 1)
	while l < n:
		if a[l] == b[l]:
			l += 1
		else:
			break
	while r >= 0:
		if a[r] == b[r]:
			r -= 1
		else:
			break
	d = set()
	ans = True
	if l <= r:
		for i in range(l, r + 1):
			v = a[i] - b[i]
			if v > 0:
				ans = False
				break
			d.add(v)
			if len(d) == 2:
				ans = False
				break
	if ans:
		print('YES')
	else:
		print('NO')


T = int(input())
for j in range(T):
	x = int(input())
	A = input()
	A = A.split()
	A = [int(A[i]) for i in range(len(A))]
	B = input()
	B = B.split()
	B = [int(B[i]) for i in range(len(A))]
	C = [0 for i in range(len(A))]
	(aux, s, r) = (-1, -1, -1)
	for i in range(len(A)):
		C[i] = B[i] - A[i]
		if C[i] != 0 and aux == -1:
			s = i
			aux = -2
		if C[i] != 0 and aux == -2:
			r = i
	if s != r:
		var = all((C[i] == C[i + 1] and C[i] > 0 and (C[i + 1] > 0) for i in range(s, r)))
	elif s == -1 and r == -1:
		var = all((C[i] == 0 for i in range(len(C))))
	else:
		var = C[s] > 0
	if var:
		print('YES')
	else:
		print('NO')


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


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	else:
		(l, k) = ([], [])
		for j in range(n):
			m = b[j] - a[j]
			if m < 0 or len(k) > 2:
				break
			else:
				l.append(m)
				if m not in k:
					k.append(m)
		if len(l) < n or len(k) > 2:
			print('NO')
		elif 0 not in l and len(k) == 2:
			print('NO')
		else:
			var = 0
			if l[0] != 0:
				for j in range(n - 1):
					if l[j + 1] - l[j] != 0:
						var += 1
				if var <= 1:
					print('YES')
				else:
					print('NO')
			else:
				for j in range(n - 1):
					if l[j + 1] - l[j] != 0:
						var += 1
				if var <= 2:
					print('YES')
				else:
					print('NO')


for _ in range(int(input())):
	n = int(input())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	bad = 0
	if a == b:
		print('YES')
		continue
	for y in range(n):
		if a[y] != b[y]:
			i = y
			break
	for y in range(n - 1, -1, -1):
		if a[y] != b[y]:
			j = y
			break
	k = b[i] - a[i]
	if k < 0:
		print('NO')
		continue
	for y in range(i + 1, j + 1):
		if b[y] - k != a[y]:
			bad = 1
			break
	if bad:
		print('NO')
	else:
		print('YES')


def function(n, a, b):
	for i in range(0, n):
		if a[i] != b[i]:
			l = i
			x = b[i] - a[i]
			break
	else:
		return 'YES'
	if x < 0:
		return 'NO'
	for i in range(l, n):
		if a[i] != b[i] - x and a[i] != b[i]:
			return 'NO'
		elif a[i] == b[i]:
			for j in range(i, n):
				if a[j] != b[j]:
					return 'NO'
			else:
				return 'YES'
	else:
		return 'YES'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(function(n, a, b))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	dif = [0] * n
	for i in range(n):
		dif[i] = m[i] - l[i]
	di = set(dif)
	if len(di) > 2 or (len(di) >= 2 and dif.count(0) == 0):
		print('NO')
	else:
		flag11 = 0
		for i in range(n):
			if dif[i] < 0:
				flag11 = -1
				print('NO')
				break
		if flag11 == 0:
			x = []
			for i in range(n):
				if dif[i] != 0:
					x.append(i)
			flag = 0
			for i in range(1, len(x)):
				if x[i] != x[i - 1] + 1:
					print('NO')
					flag = 1
					break
			if flag == 0:
				print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	out = True
	dif = []
	idx = []
	for i in range(n):
		if a[i] != b[i]:
			c = b[i] - a[i]
			dif.append(c)
			if len(idx) == 0:
				idx.append(i)
			elif i - 1 != idx[-1]:
				out = False
				break
			else:
				idx.append(i)
			if c < 0:
				out = False
				break
			elif c != dif[0]:
				out = False
				break
	if out:
		print('YES')
	else:
		print('NO')


t = int(input())
sp_ans = []
for i in range(t):
	n = int(input())
	(l, k) = (0, 0)
	ans = 0
	line = 0
	sp = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		c = b[i] - a[i]
		if c < 0:
			break
		if c > 0:
			if line == 0:
				if l == 0:
					l = 1
				else:
					break
			line = 1
			if k == 0:
				k = c
			elif k != 0 and k != c:
				break
		if c == 0:
			line = 0
	else:
		ans = 1
	if ans == 1:
		sp_ans.append('YES')
	else:
		sp_ans.append('NO')
print('\n'.join(sp_ans))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ch = 0
	l = 0
	for i in range(n):
		if a[i] != b[i] and ch != 2:
			ch = 1
			l += 1
		elif a[i] == b[i] and ch == 1:
			ch = 2
		elif a[i] != b[i] and ch == 2:
			ch = -1
		if ch == -1:
			break
	m = list()
	if ch == -1:
		print('NO')
	else:
		for i in range(n):
			q = b[i] - a[i]
			if q > 0:
				m.append(q)
			elif q < 0:
				ch = -1
		m = set(m)
		if ch == -1:
			print('NO')
		elif len(m) == 1 or len(m) == 0:
			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()))
	l = []
	for i in range(n):
		l.append(b[i] - a[i])
	flag = True
	i = 0
	while i < n:
		if l[i] != 0:
			break
		i += 1
	d = {}
	while i < n:
		if l[i] == 0:
			break
		try:
			d[l[i]] += 1
		except:
			d[l[i]] = 1
		i += 1
	while i < n:
		if l[i] != 0:
			break
		i += 1
	if i == n:
		x = list(d.keys())
		if len(x) == 0:
			print('YES')
		elif len(x) == 1 and x[0] > 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for z in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [0] * n
	for i in range(n):
		c[i] = a[i] - b[i]
	ok = True
	for i in range(n):
		if c[i] != 0:
			ok = False
			break
	if ok:
		print('YES')
		continue
	k = c[i]
	if k > 0:
		print('NO')
		continue
	else:
		for j in range(i, n):
			if c[j] != k:
				break
			c[j] = 0
	ok = True
	for i in range(n):
		if c[i] != 0:
			ok = False
			break
	if ok:
		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()))
	found = False
	less = False
	cha = None
	pr = False
	for j in range(n):
		if a[j] == b[j]:
			if less:
				found = True
		elif a[j] > b[j]:
			print('NO')
			pr = True
			break
		elif found:
			print('NO')
			pr = True
			break
		else:
			if cha == None:
				cha = a[j] - b[j]
			elif cha != a[j] - b[j]:
				print('NO')
				pr = True
				break
			less = True
	if not pr:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	diff = [0] * n
	for j in range(n):
		diff[j] = b[j] - a[j]
	ans = []
	ans.append(diff[0])
	for j in range(1, n):
		if diff[j] != diff[j - 1]:
			ans.append(diff[j])
	count = 0
	for j in range(len(ans)):
		if ans[j] != 0:
			count += 1
		if ans[j] < 0:
			count += 2
	if count <= 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = []
	f = 1
	t = -1
	for i in range(n):
		if l2[i] - l1[i] >= 0:
			l3.append(l2[i] - l1[i])
		else:
			f = 0
			break
	if f == 0:
		print('NO')
	elif l3[0] == 0 and l3[len(l3) - 1] == 0:
		count = 0
		temp = l3[0]
		for i in range(1, len(l3)):
			if l3[i] != temp:
				temp = l3[i]
				count += 1
		if count > 2:
			print('NO')
		else:
			print('YES')
	elif l3[0] == 0 and l3[len(l3) - 1] != 0:
		count = 0
		temp = l3[0]
		for i in range(1, len(l3)):
			if l3[i] != temp:
				temp = l3[i]
				count += 1
		if count > 1:
			print('NO')
		else:
			print('YES')
	elif l3[0] != 0 and l3[len(l3) - 1] == 0:
		count = 0
		temp = l3[0]
		for i in range(1, len(l3)):
			if l3[i] != temp:
				temp = l3[i]
				count += 1
		if count > 1:
			print('NO')
		else:
			print('YES')
	elif l3[0] != 0 and l3[len(l3) - 1] != 0:
		count = 0
		temp = l3[0]
		for i in range(1, len(l3)):
			if l3[i] != temp:
				temp = l3[i]
				count += 1
		if count > 0:
			print('NO')
		else:
			print('YES')


t = int(input())
s = [1] * t
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	difference = [0]
	for j in range(n):
		if b[j] < a[j]:
			s[i] = 0
			break
		elif b[j] - a[j] != difference[-1]:
			difference.append(b[j] - a[j])
	m = len(difference)
	if m > 3 or (m == 3 and difference[2] != 0):
		s[i] = 0
for k in range(t):
	if s[k] == 1:
		print('YES')
	else:
		print('NO')


def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
t = ii()
for i in range(t):
	n = ii()
	a = li()
	b = li()
	l = []
	for i in range(n):
		l.append(b[i] - a[i])
	if a == b:
		g = 0
	elif min(l) < 0:
		g = 1
	else:
		for i in range(n):
			if a[i] != b[i]:
				e = i
				break
		c = g = 0
		for i in range(n):
			if a[i] != b[i]:
				c += 1
		f = b[e] - a[e]
		if f < 0:
			g = 1
		else:
			for i in range(e, e + c):
				if b[i] - a[i] != f:
					g = 1
					break
	if g:
		print('NO')
	else:
		print('YES')


from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(10000000)

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

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

def o():
	return int(input())

def r(x):
	if type(x) == int:
		return range(x)
	else:
		return range(len(x))

def kl(con, x=0):
	if x == 0:
		print('Yes') if con else print('No')
	elif x == 1:
		print('yes') if con else print('no')
	elif x == 2:
		print('YES') if con else print('NO')
MOD = 1000000007
MAX = float('inf')
MIN = -float('inf')
p = input
for i in r(o()):
	n = o()
	l1 = op()
	l2 = op()
	f = 0
	for i in r(l1):
		if l1[i] != l2[i]:
			if f == 0:
				x = l2[i] - l1[i]
				if x < 0:
					print('NO')
					break
				f = 1
			elif f == 1:
				if l2[i] - l1[i] != x:
					print('NO')
					break
			elif f == 2 and l1[i] != l2[i]:
				print('NO')
				break
		elif f == 1:
			f = 2
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
		continue
	possible = 1
	segment = 0
	i = 0
	j = 0
	while i < n:
		diff = b[i] - a[i]
		j = i + 1
		if diff < 0:
			possible = 0
			break
		if diff != 0 and (not segment):
			segment = 1
			while j < n and b[j] - a[j] != 0:
				diff1 = b[j] - a[j]
				if diff1 != diff:
					possible = 0
					break
				j += 1
		elif diff != 0:
			possible = 0
			break
		i = j
	if not possible:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	id = 0
	while id < n and a[id] == b[id]:
		id += 1
	fl = False
	if id < n:
		if b[id] - a[id] < 0:
			print('NO')
			continue
	while id + 1 < n and a[id + 1] != b[id + 1]:
		if b[id] - a[id] < 0 or a[id + 1] - b[id + 1] != a[id] - b[id]:
			print('NO')
			fl = True
			break
		id += 1
	if fl:
		continue
	for j in range(id + 1, n):
		if a[j] != b[j]:
			fl = True
			print('NO')
			break
	if not fl:
		print('YES')


from sys import stdin
from collections import deque
t = int(stdin.readline().strip())
for cas in range(t):
	n = int(stdin.readline().strip())
	s = list(map(int, stdin.readline().strip().split()))
	s1 = list(map(int, stdin.readline().strip().split()))
	aux = deque([])
	for i in range(n):
		aux.append(s[i] - s1[i])
	l = n
	r = -1
	for i in range(n):
		if aux[i] != 0:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if aux[i] != 0:
			r = i
			break
	st = set()
	for i in range(l, r + 1):
		st.add(aux[i])
	st = list(st)
	if len(st) == 0 or (len(st) == 1 and st[0] < 0):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if l1 == l2:
		print('YES')
		continue
	flag = 0
	diff1 = 0
	diff2 = 0
	for j in range(n):
		if l1[j] < l2[j]:
			diff1 = l2[j] - l1[j]
			in1 = j
			break
		if l1[j] > l2[j]:
			flag = 1
			break
	for j in range(n - 1, -1, -1):
		if l1[j] < l2[j]:
			diff2 = l2[j] - l1[j]
			in2 = j
			break
		if l1[j] > l2[j]:
			flag = 1
			continue
	if flag == 1:
		print('NO')
		continue
	if diff1 != diff2:
		print('NO')
		continue
	else:
		for j in range(in1, in2 + 1):
			l1[j] = l1[j] + diff1
		if l1 != l2:
			print('NO')
		else:
			print('YES')


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	d = 0
	s = 0
	res = True
	for i in range(n):
		if a[i] != b[i]:
			if a[i] > b[i]:
				res = False
				break
			if d == 0:
				s = b[i] - a[i]
				d = 1
			elif d == 1:
				if s != b[i] - a[i]:
					res = False
					break
			elif d == 2:
				res = False
				break
		elif d == 1:
			d = 2
	print('YES' if res else 'NO')


t = int(input())
for r in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	flag = 1
	diff = -9999999
	count = 0
	count0 = 0
	for i in range(0, n):
		if l1[i] - l2[i] != diff:
			diff = l1[i] - l2[i]
			count += 1
			if l1[i] - l2[i] == 0:
				count0 += 1
		if l1[i] - l2[i] > 0:
			flag = 0
	if flag == 1 and count - count0 <= 1:
		print('YES')
	else:
		print('NO')


mod = 10 ** 9 + 7
import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def main():
	x = inin()
	for _ in range(x):
		n = inin()
		a = ain()
		b = ain()
		d = {}
		t = 0
		ans = 'YES'
		xx = 0
		for i in range(n):
			if b[i] - a[i] == 0 and t == 0:
				continue
			elif b[i] - a[i] > 0 and t == 0:
				t = 1
				xx = b[i] - a[i]
			elif b[i] - a[i] < 0 and t == 0:
				ans = 'NO'
				break
			elif t == 1:
				if b[i] - a[i] == xx:
					continue
				elif b[i] - a[i] == 0:
					t = 2
					x = 0
				else:
					ans = 'NO'
					break
			elif t == 2:
				if b[i] - a[i] == 0:
					continue
				else:
					ans = 'NO'
					break
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


a = int(input())
for i in range(a):
	n = int(input())
	t1 = [int(s) for s in input().split()]
	t2 = [int(s) for s in input().split()]
	phase = 0
	bon = True
	diff = 0
	for j in range(n):
		if phase == 0 and t1[j] != t2[j]:
			if t1[j] < t2[j]:
				diff = t2[j] - t1[j]
				phase = 1
			else:
				bon = False
		if phase == 1 and t1[j] != t2[j] - diff:
			if t1[j] == t2[j]:
				phase = 2
			else:
				bon = False
		if phase == 2 and t1[j] != t2[j]:
			bon = False
	if bon:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	k1 = -1
	k2 = -1
	f = True
	for i in range(n):
		if arr1[i] == arr2[i]:
			if k1 != -1:
				k2 = 1
			continue
		elif arr1[i] < arr2[i]:
			if k2 == 1:
				print('NO')
				f = False
				break
			if k1 == -1:
				k1 = arr2[i] - arr1[i]
			elif arr2[i] - arr1[i] != k1:
				print('NO')
				f = False
				break
		else:
			print('NO')
			f = False
			break
	if f:
		print('YES')


for j in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	k = 0
	last = 0
	ans = 'YES'
	for i in range(n):
		if b[i] - a[i] != 0:
			if b[i] - a[i] != k:
				if k == 0:
					k = b[i] - a[i]
					last = i
				else:
					ans = 'NO'
			elif i == last + 1:
				last += 1
			else:
				ans = 'NO'
	if k < 0:
		ans = 'NO'
	print(ans)


import sys
(mod, MOD) = (1000000007, 998244353)

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

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

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

def check(C):
	count = 0
	for i in range(n):
		if C[i] < 0:
			return False
		if C[i] == C[0]:
			count += 1
	if count == n:
		return True
	for i in range(n):
		if C[i] != 0:
			index1 = i
			break
	for i in range(n - 1, -1, -1):
		if C[i] != 0:
			index2 = i
			break
	value = C[index1]
	for i in range(index1, index2 + 1):
		if C[i] != value:
			return False
	return True
T = int(input())
while T:
	n = int(input())
	A = get_array()
	B = get_array()
	C = []
	for i in range(n):
		C.append(B[i] - A[i])
	if check(C):
		print('YES')
	else:
		print('NO')
	T -= 1


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	n = get_int()
	lst1 = get_int_list()
	lst2 = get_int_list()
	i = 0
	while i < n and lst1[i] == lst2[i]:
		i += 1
	if i < n:
		diff = lst2[i] - lst1[i]
		if diff > 0:
			equal = True
			first_time = True
			while i < n:
				if lst2[i] - lst1[i] == diff:
					i += 1
				elif first_time:
					diff = 0
					first_time = False
				else:
					equal = False
					break
		else:
			equal = False
	else:
		equal = True
	if equal:
		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()))
	diff = [b[i] - a[i] for i in range(N)]
	flag = True
	count = 0
	v = 0
	for i in range(N):
		if diff[i] < 0:
			flag = False
			break
		elif diff[i] > 0:
			if count == 0:
				count += 1
				v = diff[i]
			elif v != diff[i]:
				flag = False
				break
		else:
			v = 0
	if flag == True:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def bfs(g, st):
	visited = [-1] * len(g)
	visited[st] = 0
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == -1:
				visited[i] = visited[s] + 1
				queue.append(i)
	return visited

def dfsusingstack(v, st):
	d = deque([])
	visited = [0] * len(v)
	d.append(st)
	new = []
	visited[st] = 1
	while len(d) != 0:
		curr = d.pop()
		new.append(curr)
		for i in v[curr]:
			if visited[i] == 0:
				visited[i] = 1
				d.append(i)
	return new

def sieve(a, n):
	for i in range(3, n + 1, 2):
		a[i] = 1
	for i in range(3, n + 1, 2):
		for j in range(i * i, n + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	n = int(inp())
	a = lis()
	b = lis()
	diff = []
	for i in range(n):
		diff.append(a[i] - b[i])
		if diff[i] > 0:
			print('NO')
			return
	if len(set(diff)) > 2:
		print('NO')
		return
	if len(set(diff)) == 1:
		print('YES')
		return
	if diff.count(0) == 0:
		print('NO')
		return
	ind = []
	for i in range(0, n):
		if diff[i] != 0:
			ind.append(i)
			break
	for i in range(ind[0], n):
		if diff[i] == 0:
			ind.append(i)
			break
	if len(ind) == 1:
		print('YES')
		return
	for i in range(ind[1], n):
		if diff[i] != 0:
			print('NO')
			return
	print('YES')
testcase(int(inp()))


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	d = [0] * (n + 2)
	flag = True
	c = 0
	for i in range(n):
		d[i + 1] = b[i] - a[i]
	for i in range(len(d) - 1):
		if d[i] < 0:
			flag = False
		if d[i] != d[i + 1]:
			c += 1
	if flag == False or c > 2:
		print('NO')
	else:
		print('YES')
	t -= 1


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Query.append((N, A, B))
for (N, A, B) in Query:
	ok = True
	dif = 0
	for i in range(N):
		if A[i] != B[i]:
			if dif == 0:
				d = A[i] - B[i]
				if d > 0:
					ok = False
				dif += 1
			elif dif == 1:
				if A[i] - B[i] != d:
					ok = False
			else:
				ok = False
		elif dif == 0:
			continue
		elif dif == 1:
			dif += 1
	print('YES' if ok else 'NO')


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()))
	c = [0] * (N + 1)
	ans = 'YES'
	for i in range(N):
		c[i] = b[i] - a[i]
	prv = 0
	cnt = 0
	for i in range(N + 1):
		if c[i] < 0:
			ans = 'NO'
		if c[i] != prv:
			prv = c[i]
			cnt += 1
	if cnt > 2:
		ans = 'NO'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = [a[i] - b[i] for i in range(n)]
	if any((x > 0 for x in diff)):
		print('NO')
		continue
	pre = 0
	c = 0
	for x in diff:
		if pre != x:
			if c and x:
				print('NO')
				break
			c += 1
		pre = x
	else:
		print('YES')


def f():
	n = int(input())
	a = input().split()
	b = input().split()
	c = [int(a[i]) - int(b[i]) for i in range(n)]
	q = [i for i in range(n) if c[i] != 0]
	f = True
	if len(q) != 0:
		w = c[q[0]]
		if w > 0:
			f = not f
		i = 0
		while f and i < len(q) - 1:
			if not (q[i] + 1 == q[i + 1] and c[q[i + 1]] == c[q[0]]):
				f = False
			i += 1
	if f:
		print('YES')
	else:
		print('NO')
p = int(input())
i = 0
while i < p:
	f()
	i += 1


for _ in range(int(input())):
	N = int(input())
	flag = 0
	m = 0
	h = 0
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for i in range(N):
		if flag == 0:
			if A[i] != B[i]:
				if A[i] > B[i]:
					m = 1
					flag = 1
				else:
					k = B[i] - A[i]
					flag = 1
		elif flag == 1 and A[i] == B[i]:
			h = 1
		elif A[i] != B[i] and h == 0:
			if k != B[i] - A[i]:
				m = 1
		elif A[i] != B[i] and h == 1:
			m = 1
		if m == 1:
			break
	if m == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for oo in range(t):
	size = int(input())
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()]
	start = -1
	end = -1
	diff = 0
	for i in range(size):
		if a[i] != b[i] and start < 0:
			start = i
			end = i + 1
			diff = b[i] - a[i]
		elif a[i] != b[i] and start >= 0:
			end = i + 1
	if diff < 0:
		print('NO')
		continue
	for i in range(start, end):
		a[i] += diff
	if a == b:
		print('YES')
	else:
		print('NO')


t_cases = int(input())
for t in range(t_cases):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if A == B:
		print('YES')
		continue
	(start, end) = (-1, n)
	for i in range(n):
		if A[i] != B[i]:
			start = i
			break
	for j in range(n):
		if A[n - j - 1] != B[n - j - 1]:
			end = n - j - 1
			break
	if start == -1 or end == n:
		print('NO')
		continue
	y1 = A[start:end + 1]
	y2 = B[start:end + 1]
	dif = set()
	for k in range(len(y1)):
		dif.add(y2[k] - y1[k])
	if len(dif) == 1 and A[start] - B[start] < 0:
		print('YES')
	else:
		print('NO')


t = int(input())

def push(l, i, j, k):
	for m in range(i, j + 1):
		l[m] += k
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	i = 0
	indice = 0
	diff = 0
	while diff == 0 and i < n:
		diff = b[i] - a[i]
		indice = i
		i += 1
	if diff == 0:
		print('YES')
	elif diff < 0:
		print('NO')
	else:
		ct = 0
		for i in range(n):
			if b[i] - a[i] == diff:
				ct += 1
		push(a, indice, indice + ct - 1, diff)
		if a == b:
			print('YES')
		else:
			print('NO')


def v(n, a, b):
	q = []
	nu = []
	for i in range(n):
		q.append(b[i] - a[i])
		if b[i] != a[i]:
			nu.append(b[i] - a[i])
	l = 0
	w = []
	for i in range(n):
		if q[i] != 0:
			l += 1
		elif l:
			w.append(l)
			l = 0
	if l:
		w.append(l)
	if min(q) >= 0 and len(w) <= 1 and (len(set(nu)) < 2):
		return 'YES'
	else:
		return 'NO'
an = []
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	an.append(v(n, a, b))
print(*an, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	smin = -1
	s = 0
	if n == 1 and b[0] - a[0] >= 0:
		print('YES')
		continue
	if n == 1 and b[0] - a[0] < 0:
		print('NO')
		continue
	for i in range(n):
		if a[i] != b[i]:
			smin = i
			break
	if smin == -1:
		print('YES')
		continue
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			smax = i
			break
	for i in range(smin, smax + 1):
		if b[i] - a[i] == b[smin] - a[smin] and b[i] - a[i] > 0:
			continue
		else:
			s = -1
			break
	if s == -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()))
	c = []
	d = []
	flag = 0
	k = 0
	for i in range(n):
		t = b[i] - a[i]
		c.append(t)
		d.append(t)
	e = []
	d = list(set(d))
	if min(d) < 0:
		print('NO')
	elif len(d) == 1:
		print('YES')
	elif len(d) > 2:
		print('NO')
	else:
		d.sort()
		if d[0] != 0:
			print('NO')
		else:
			p = d[1]
			for i in range(n):
				if c[i] == p:
					e.append(i)
			if e[0] + len(e) - 1 == e[-1]:
				print('YES')
			else:
				print('NO')


t = int(input())
for k in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if A == B:
		print('YES')
	else:
		i = -1
		j = 0
		l = 0
		d = 0
		K = 'Y'
		while K == 'Y':
			i = i + 1
			if i >= n:
				break
			if B[i] - A[i] != 0 and j == 0:
				d = B[i] - A[i]
				j = 1
				if d < 0:
					print('NO')
					K = 'N'
					break
			if B[i] - A[i] != d and B[i] - A[i] != 0:
				print('NO')
				K = 'N'
				break
			if B[i] - A[i] != d and B[i] - A[i] == 0 and (l == 0):
				l = 1
			if B[i] - A[i] != 0 and l != 0:
				print('NO')
				K = 'N'
				break
		if K == 'Y':
			print('YES')


for __ in range(int(input())):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	num = 0
	flag = 0
	ans = 'YES'
	for i in range(n):
		if ar1[i] > ar2[i]:
			ans = 'NO'
		elif ar1[i] == ar2[i]:
			num = 0
		elif ar1[i] - ar2[i] != num and flag == 1:
			ans = 'NO'
		elif ar1[i] - ar2[i] != num:
			num = ar1[i] - ar2[i]
			flag = 1
	print(ans)


from itertools import groupby
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()]
	C = [B[i] - A[i] for i in range(len(A))]
	D = sorted([(y, len(list(x))) for (y, x) in groupby(C)], key=lambda a: abs(a[0]))
	if len(D) <= 3 and D[-1][0] >= 0 and ([x[0] for x in D].count(0) >= len(D) - 1):
		res = 'YES'
	else:
		res = 'NO'
	print(res)


tc = int(input())
for _ in range(tc):
	n = int(input())
	ar = list(map(int, input().split()))
	ar1 = list(map(int, input().split()))
	k = 0
	count = 0
	for i in range(n):
		if ar1[i] > ar[i]:
			count = ar1[i] - ar[i]
			for k in range(i, n):
				if ar1[k] > ar[k]:
					ar[k] += count
				else:
					break
			break
	if ar == ar1:
		print('YES')
	else:
		print('NO')


for _ in ' ' * int(input()):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	z = 0
	e = 'YES'
	n = 0
	k = 0
	g = 0
	for i in range(a):
		c[i] = c[i] - b[i]
	for i in range(a):
		if c[i] < 0:
			e = 'NO'
			break
		if c[i] != 0:
			if g == 0:
				k = c[i]
				n = i
				g = 1
				k = c[i]
			elif i - n == 1 and k == c[i]:
				n = i
			else:
				e = 'NO'
				break
	print(e)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 0
	t = float('inf')
	start = 0
	for j in range(n):
		if a[j] != b[j]:
			if start == 2:
				res = 1
				break
			start = 1
			if a[j] > b[j]:
				res = 1
				break
			if t == float('inf'):
				t = b[j] - a[j]
			if b[j] - a[j] != t:
				res = 1
				break
		elif start == 1:
			start = 2
	print('YNEOS'[res::2])


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
	g = 0
	k = 0
	res = 1
	for j in range(n):
		if a[j] != b[j]:
			if g == 1:
				res = -1
				break
			if f == 0:
				k = b[j] - a[j]
				f = 1
				if k < 0:
					res = -1
					break
			elif a[j] + k != b[j]:
				res = -1
				break
		elif f == 1:
			g = 1
	if res == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	arr = []
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 'YES'
	j = 0
	while j < n and a[j] == b[j]:
		j += 1
	while j < n and a[j] != b[j]:
		arr.append(a[j] - b[j])
		j += 1
	while j < n and a[j] == b[j]:
		j += 1
	if j < n:
		ans = 'NO'
	else:
		if len(arr) > 0 and len(list(set(arr))) > 1:
			ans = 'NO'
		if len(arr) > 0 and list(set(arr))[0] > 0:
			ans = 'NO'
	print(ans)


T = int(input())
for t_i in range(T):
	n = int(input())
	A = input().split()
	A = [int(k) for k in A]
	B = input().split()
	B = [int(k) for k in B]
	D = []
	for i in range(n):
		D.append(B[i] - A[i])
	j = 0
	while j < n and D[j] == 0:
		j += 1
	if j == n:
		print('YES')
		continue
	d = D[j]
	if d < 0:
		print('NO')
		continue
	while j < n and D[j] == d:
		j += 1
	if j == n:
		print('YES')
		continue
	while j < n and D[j] == 0:
		j += 1
	if j < n:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c1 = []
	dic = {}
	for i in range(0, n):
		c1.append(b[i] - a[i])
	left = 1
	right = 0
	c = 1
	l = 0
	m = 0
	flag = 0
	for i in range(0, n):
		if c1[i] == 0:
			continue
		elif c1[i] < 0:
			flag = 1
			break
		elif l == 0:
			l = 1
			m = c1[i]
			left = i
		elif m == c1[i] and i - left == 1:
			left = i
			continue
		elif m != c1[i] or (m == c1[i] and left - i != 1):
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	(x, flg) = (-10000, 0)
	for i in range(n):
		if l[i] != ll[i]:
			x = abs(l[i] - ll[i])
			flg = 1
			break
	if flg == 0:
		print('YES')
	else:
		i = 0
		while i < n and l[i] == ll[i]:
			i += 1
		while i < n and l[i] != ll[i]:
			if l[i] < ll[i]:
				l[i] += x
			i += 1
		flgg = 0
		for i in range(n):
			if l[i] != ll[i]:
				flgg = 1
				break
		if flgg == 1:
			print('NO')
		else:
			print('YES')


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input()
	A = list(map(int, list(a.split())))
	b = input()
	B = list(map(int, list(b.split())))
	c = [0] * n
	for i in range(n):
		c[i] = B[i] - A[i]
	d = {}
	flag = 0
	for i in range(n):
		if c[i] < 0:
			print('NO')
			flag = 1
			break
		elif c[i] != 0:
			if d == {}:
				d[c[i]] = 1
			elif c[i] not in d:
				print('NO')
				flag = 1
				break
			elif c[i] != c[i - 1]:
				print('NO')
				flag = 1
				break
	if flag == 0:
		print('YES')


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = [b[k] - a[k] for k in range(n)]
		f = 0
		ans = 0
		c = [0] + c + [0]
		for k in range(1, n + 1):
			if c[k] < 0:
				ans = -1
				break
		f = 0
		for k in range(1, n + 1):
			if c[k] != 0 and f == 0:
				t = c[k]
				f = 1
			elif c[k] != 0 and f == 1:
				if c[k] != t:
					ans = -2
					break
			elif f == 1 and c[k] == 0:
				f = -1
			elif f == -1 and c[k] != 0:
				ans = -3
				break
		if ans < 0:
			print('NO')
		else:
			print('YES')
main()


for k in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	i = 0
	j = n - 1
	flag = 0
	while i < j and (arr[i] == ls[i] or arr[j] == ls[j]):
		if arr[i] == ls[i]:
			i += 1
		if arr[j] == ls[j]:
			j -= 1
	dif = ls[i] - arr[i]
	for i in range(i, j + 1):
		if ls[i] - arr[i] == dif and dif >= 0:
			pass
		else:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	diff = [b[i] - a[i] for i in range(n)]
	has_negative = any([x < 0 for x in diff])
	cnt = len(set(diff))
	if cnt > 2 or has_negative:
		print('NO')
	elif cnt == 1:
		print('YES')
	else:
		(first, last) = (0, n - 1)
		while diff[first] == 0:
			first += 1
		while diff[last] == 0:
			last -= 1
		if len(set(diff[first:last + 1])) == 1:
			print('YES')
		else:
			print('NO')


from operator import add
test_cases = int(input())
final_output = []
while test_cases > 0:
	strings = []
	store = []
	test_cases -= 1
	n = int(input())
	a = input().split(' ')
	a = [int(i) for i in a]
	b = input().split(' ')
	b = [int(i) for i in b]
	diff = [b[i] - a[i] for i in range(0, n)]
	if min(diff) < 0:
		final_output += [0]
		continue
	if a == b:
		final_output += [1]
		continue
	for i in range(0, len(diff)):
		if diff[i] != 0:
			store += [diff[i]]
			if i == len(diff) - 1:
				strings += [store]
		elif diff[i] == 0:
			if store != []:
				strings += [store]
				store = []
	if len(strings) > 1:
		final_output += [0]
	elif strings != []:
		if len(set(strings[0])) > 1:
			final_output += [0]
		elif int(strings[0][0]) < 0:
			final_output += [0]
		else:
			final_output += [1]
for i in final_output:
	if i == 0:
		print('NO')
	if i == 1:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	negi = 0
	r1 = 1
	negg = []
	c = 1
	t = 0
	g = 0
	neg = 0
	for i in range(n):
		if a[i] - b[i] != 0 and c == 1:
			if a[i] - b[i] > 0:
				g = 1
				break
			elif a[i] - b[i] < 0:
				negi = a[i] - b[i]
				negg.append(r1)
				neg = 1
				t = 1
			c = 0
		elif a[i] - b[i] != 0 and neg == 1:
			if a[i] - b[i] > 0:
				g = 1
				break
			elif a[i] - b[i] != negi:
				g = 1
				break
			else:
				negg.append(r1)
				t = 1
		elif a[i] - b[i] == 0 and t == 1:
			r1 = 2
			r = 2
	if len(set(negg)) >= 2 or g == 1:
		print('NO')
	else:
		print('YES')


from itertools import groupby
from operator import itemgetter, sub

def main():
	for _ in range(int(input())):
		(_, l) = (input(), list(map(itemgetter(0), groupby(map(sub, *[map(int, s.split()) for s in (input(), input())])))))
		print(('NO', 'YES')[all((a <= 0 for a in l)) and 4 > len(l) < 2 + l.count(0)])
main()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = defaultdict(list)
	k = []
	f = 1
	for i in range(n):
		k.append(b[i] - a[i])
		if k[-1] < 0:
			f = 0
			break
	if f == 0:
		print('NO')
	elif len(set(k)) > 2:
		print('NO')
	else:
		for i in range(n):
			if k[i] != 0:
				d[k[i]].append(i)
		if 0 not in set(k) and len(set(k)) >= 2:
			print('NO')
		else:
			for i in d:
				if i != 0:
					for j in range(1, len(d[i])):
						if d[i][j] != d[i][j - 1] + 1:
							f = 0
			if f == 0:
				print('NO')
			else:
				print('YES')


for _ in range(int(input())):
	temp = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	i = 0
	while i < temp and a[i] == b[i]:
		i += 1
	if i == temp:
		print('YES')
		continue
	diff = b[i] - a[i]
	if diff < 0:
		print('NO')
		continue
	while i < temp and a[i] + diff == b[i]:
		i += 1
	while i < temp and a[i] == b[i]:
		i += 1
	if i == temp:
		print('YES')
		continue
	print('NO')


T = int(input())
while T > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [b[i] - a[i] for i in range(n)]
	ans = 'YES'
	diff = 0
	i = 0
	while i < n:
		if c[i] < 0:
			ans = 'NO'
		elif c[i] > 0:
			if diff != 0 and c[i] != diff:
				ans = 'NO'
			diff = c[i]
		elif diff != 0:
			diff = 6969696969
		i += 1
	print(ans)
	T -= 1


import math

def getAns(li1, li2):
	li3 = []
	diff = 0
	theDiff = 0
	firstOccurrence = True
	onARoll = False
	for i in range(len(li1)):
		diff = li2[i] - li1[i]
		if diff != 0:
			if diff < 0:
				return 'NO'
			if firstOccurrence:
				firstOccurrence = False
				theDiff = diff
			elif not firstOccurrence and (not onARoll):
				return 'NO'
			elif theDiff != diff:
				return 'NO'
			onARoll = True
		else:
			onARoll = False
	return 'YES'
n = int(input())
for i in range(n):
	input()
	print(getAns([int(x) for x in input().split(' ')], [int(y) for y in input().split(' ')]))


n1 = int(input())
for j in range(n1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = 1
	t = 0
	s = 0
	for i in range(n):
		if t == 0:
			if a[i] - b[i] != 0:
				t = 1
				di = a[i] - b[i]
				if di > 0:
					f = 0
					break
		if t == 1:
			if a[i] - b[i] == 0:
				s = 1
			if s == 1:
				if a[i] != b[i]:
					f = 0
					break
			if a[i] - b[i] != di and s == 0:
				f = 0
				break
	if f == 1:
		print('YES')
	else:
		print('NO')


def func():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = []
	s = set()
	cond = False
	for i in range(n):
		x = b[i] - a[i]
		d.append(x)
		if x > 0:
			s.add(x)
		if x < 0:
			cond = True
			break
	if len(s) > 1 or cond == True:
		print('NO')
	else:
		for i in range(1, n - 1):
			if d[i] == 0:
				if d[i - 1] > 0 and d[i + 1] > 0:
					cond = True
					break
		if cond == True:
			print('NO')
		else:
			print('YES')
t = int(input())
for i in range(t):
	func()


def func(n, a, b):
	d = [b[i] - a[i] for i in range(n)]
	for i in range(n):
		if d[i] < 0:
			return False
	d.insert(0, 0)
	d.append(0)
	counter = 0
	for j in range(0, len(d) - 1):
		if d[j] != d[j + 1]:
			counter += 1
	if counter > 2:
		return False
	else:
		return True
t = int(input())
result = []
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if func(n, a, b):
		result.append('YES')
	else:
		result.append('NO')
print(*result, sep='\n')


import sys
tests = int(sys.stdin.readline())
for _ in range(tests):
	n = int(sys.stdin.readline())
	arr1 = list(map(int, sys.stdin.readline().split()))
	arr2 = list(map(int, sys.stdin.readline().split()))
	result = []
	ok = True
	for i in range(n):
		if arr1[i] != arr2[i]:
			result.append([arr1[i] - arr2[i], i])
			if arr1[i] > arr2[i]:
				ok = False
	if len(result) == 0:
		print('YES')
	else:
		resultt = sorted(result, key=lambda el: el[0])
		for i in range(1, len(resultt)):
			if resultt[i][0] != resultt[i - 1][0]:
				ok = False
				break
		resultt2 = sorted(result, key=lambda el: el[1])
		for i in range(1, len(resultt2)):
			if resultt2[i][0] == resultt2[i - 1][0] and resultt2[i][1] != resultt2[i - 1][1] + 1:
				ok = False
				break
		if ok:
			print('YES')
		else:
			print('NO')


for x in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c, f) = ([], 0)
	for y in range(n):
		if b[y] - a[y] < 0:
			f = 1
			break
		else:
			c.append(str(b[y] - a[y]))
	if f == 1:
		print('NO')
	else:
		c.insert(0, '0')
		c.append('0')
		for i in range(len(c) - 1):
			if c[i] != c[i + 1]:
				f += 1
			if f > 2:
				break
		if f > 2:
			print('NO')
		else:
			print('YES')


times = input()
outs = []
for q in range(0, int(times)):
	cbd = 'YES'
	l = int(input())
	n = input()
	a = n.split(' ')
	m = input()
	b = m.split(' ')
	diff = 0
	wasdiff = 0
	nowzero = False
	chg = True
	for w in range(0, l):
		diff = int(b[w]) - int(a[w])
		if chg == False and diff == 0:
			nowzero = True
		if chg == False:
			if diff != 0:
				if nowzero == True or diff != wasdiff:
					cbd = 'NO'
		if nowzero == False and diff != 0 and (chg == True):
			wasdiff = diff
			chg = False
		if diff < 0:
			cbd = 'NO'
	if cbd == 'NO':
		outs.append('NO')
	else:
		outs.append('YES')
for r in range(0, len(outs)):
	print(outs[r])


for q in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(map(int, input().split()))
	ans = -1
	for q in range(len(a)):
		if a[q] != s[q] and ans == -1:
			ans = s[q] - a[q]
			if ans < 0:
				print('NO')
				break
		elif a[q] != s[q] and (ans == -2 or ans != s[q] - a[q]):
			print('NO')
			break
		elif a[q] == s[q] and ans > 0:
			ans = -2
	else:
		print('YES')


from collections import Counter
from collections import defaultdict
import math
import bisect
t = int(input())
for i in range(0, t):
	n = int(input())
	l = list()
	c = list()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(0, n):
		if a[i] != b[i]:
			l.append(a[i] - b[i])
			c.append(i)
	f = 1
	for i in range(0, len(c) - 1):
		if c[i + 1] - c[i] != 1:
			f = 0
			break
	s = list(set(l))
	if len(s) == 0:
		print('YES')
		continue
	if len(s) < 2 and f == 1 and (s[0] <= 0):
		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()))
	c = [b[i] - a[i] for i in range(n)]
	last = None
	fail = False
	if any((x < 0 for x in c)):
		fail = True
	for item in c:
		if last == None:
			if item == 0:
				continue
			else:
				last = item
		elif item == 0:
			last = 0
		elif item != last:
			fail = True
			break
	if fail:
		print('NO')
	else:
		print('YES')


q = int(input())
for i in range(q):
	n = int(input())
	a = [int(a) for a in input().split(' ')]
	b = [int(b) for b in input().split(' ')]
	diffstart = False
	count = 0
	i = 0
	change = 0
	printed = 0
	answered = False
	for i in range(n):
		if a[i] == b[i] and diffstart == False:
			continue
		elif a[i] == b[i] and diffstart == True:
			diffstart = False
			change += 1
		elif a[i] != b[i]:
			if diffstart == False:
				diff = b[i] - a[i]
				diffstart = True
				change += 1
				if diff < 0:
					print('NO')
					change = 0
					printed += 1
					answered = True
					break
			elif diffstart == True:
				if b[i] - a[i] != diff:
					print('NO')
					change = 0
					printed += 1
					answered = True
					break
		elif a[i] == b[i] and diffstart == True:
			diffstart = False
	if answered == False:
		if change == 2 and diffstart == False:
			print('YES')
		elif change == 1 and diffstart == True:
			print('YES')
		elif change == 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()))
	l = 0
	f = g = False
	for i in range(n):
		d = b[i] - a[i]
		if d:
			if g:
				print('NO')
				break
			f = True
			if d < 0 or (l and l != d):
				print('NO')
				break
			l = d
		else:
			if f:
				g = True
			l = 0
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = 0
	r = 0
	c = 0
	i = 0
	while i < n:
		if a[i] != b[i]:
			c = c + 1
			l = i
			while a[i] != b[i]:
				i = i + 1
				if i == n:
					break
			r = i - 1
		else:
			i = i + 1
	if c == 1:
		d = b[l] - a[l]
		if d > 0:
			f = 0
			for i in range(l, r + 1):
				if d != b[i] - a[i]:
					f = 1
					break
			if f:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')
	elif c == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	l = list(map(int, input().split()))
	h = [l[i] - k[i] for i in range(n)]
	d = []
	f = 0
	for i in range(n - 1):
		if h[i] < 0:
			f = 1
			break
		if h[i] != h[i + 1]:
			d.append(h[i])
	if h[-1] < 0:
		f = 1
	d.append(h[-1])
	if f == 1 or len(d) > 3:
		print('NO')
	elif len(d) == 3:
		if d[0] == 0 and d[-1] == 0:
			print('YES')
		else:
			print('NO')
	elif len(d) == 2:
		if d[0] == 0 or d[1] == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = 1
	ooo = 0
	ans = 'YES'
	if a == b:
		print('YES')
		continue
	for i in range(n):
		if a[i] != b[i]:
			if ooo == 1:
				ans = 'NO'
				break
			if f == 1:
				k = b[i] - a[i]
				f = 0
			elif b[i] - a[i] != k:
				ans = 'NO'
				break
			if k < 0:
				ans = 'NO'
				break
		else:
			ooo = [0, 1][f == 0]
	print(ans)


def check(arr1, arr2):
	i = 0
	k = 0
	while i < len(arr1):
		if arr1[i] == arr2[i]:
			pass
		elif arr2[i] - arr1[i] < 0:
			return False
		elif k == 0:
			k = arr2[i] - arr1[i]
			lastIndex = i
		elif arr1[i] + k == arr2[i] and i == lastIndex + 1:
			lastIndex = i
		else:
			return False
		i += 1
	return True
t = int(input())
while t > 0:
	n = int(input())
	arr1 = list(map(int, input().rstrip().split()))
	arr2 = list(map(int, input().rstrip().split()))
	result = check(arr1, arr2)
	if result:
		print('YES')
	else:
		print('NO')
	t -= 1


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


t = int(input())
for ti in range(t):
	try:
		n = int(input())
		a = input().split()
		b = input().split()
		for j in range(n):
			a[j] = int(a[j])
			b[j] = int(b[j])
		for w in range(n):
			if a[w] != b[w]:
				diff = b[w] - a[w]
				if diff < 0:
					raise Exception
				newdiff = diff
				for y in range(w + 1, n):
					newdiff = b[y] - a[y]
					if newdiff != diff and newdiff != 0:
						raise Exception
					y += 1
					if newdiff == 0:
						for r in range(y, n):
							if a[r] != b[r]:
								raise Exception
						break
				break
		print('YES')
	except:
		print('NO')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	a = inpl()
	b = inpl()
	c = []
	s = set()
	for i in range(n):
		c.append(b[i] - a[i])
		if b[i] != a[i]:
			s.add(b[i] - a[i])
	if len(list(s)) >= 2 or min(c) < 0:
		print('NO')
		continue
	cnt = 0
	now = c[0]
	for i in range(n):
		if now != c[i]:
			cnt += 1
			now = c[i]
	f = True
	if c[0]:
		if cnt > 1:
			f = False
	elif cnt > 2:
		f = False
	print('YES' if f else 'NO')


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	if a == b:
		print('YES')
	else:
		for i in range(n):
			c.append(a[i] - b[i])
		s = set(c)
		d = list(s)
		if len(d) > 2:
			print('NO')
		elif len(d) == 1:
			if d[0] <= 0:
				print('YES')
			else:
				print('NO')
		else:
			d.sort()
			flag = 0
			for i in range(len(d)):
				if d[i] == 0:
					flag = 1
			if flag == 0:
				print('NO')
			else:
				d.sort()
				if d.index(0) == 0 and len(d) == 2:
					print('NO')
				else:
					e = []
					for i in range(n):
						if d[0] == c[i]:
							e.append(i)
					flag1 = 0
					for i in range(1, len(e)):
						if e[i] - e[i - 1] > 1:
							flag1 = 1
							break
					if flag1 == 1:
						print('NO')
					else:
						print('YES')


for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for k in range(n):
		A[k] -= B[k]
	p = True
	x = False
	P = True
	for j in range(n):
		if A[j] > 0:
			P = False
		if A[j] != 0 and p:
			p = False
			this = A[j]
		elif x and A[j] != 0:
			P = False
		elif A[j] != 0 and (not p):
			if A[j] != this:
				P = False
		elif A[j] == 0 and (not p):
			x = True
	if P:
		print('YES')
	else:
		print('NO')


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split(' ')))
	b = list(map(int, sys.stdin.readline().split(' ')))
	able = True
	stopped = False
	k = None
	for j in range(n):
		if b[j] > a[j]:
			if k == None:
				k = b[j] - a[j]
			elif stopped or k != b[j] - a[j]:
				able = False
		elif b[j] < a[j]:
			able = False
		elif k != None:
			stopped = True
	print('YES') if able else print('NO')


a = int(input())
for _ in range(a):
	n = int(input())
	flag = list(map(int, input().split()))
	flag1 = list(map(int, input().split()))
	k = 0
	fake = flag1.copy()
	if flag == flag1:
		print('YES')
		continue
	elif n == 1 and flag1[0] - flag[0] < 0:
		print('NO')
		continue
	for i in range(n):
		res = flag1[i] - flag[i]
		if res < 0:
			break
		if res == 0 and k != 0:
			break
		elif res == 0:
			continue
		else:
			if k == 0:
				k = res
			if k != res:
				break
			fake[i] = fake[i] - res
	if fake == flag:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	c = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	for j in range(len(a)):
		if a[j] < b[j]:
			t = b[j] - a[j]
			for k in range(j, n):
				if a[k] < b[k]:
					a[k] += t
				else:
					break
			break
	if a == b:
		print('YES')
	else:
		print('NO')


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	i = 0
	not_equal = []
	while i < n:
		if arr[i] == brr[i]:
			i += 1
		else:
			j = i
			while j < n and arr[j] != brr[j]:
				j += 1
			not_equal.append((i, j - 1))
			i = j
	if len(not_equal) > 1:
		print('NO')
	elif len(not_equal) == 0:
		print('YES')
	else:
		hogaya = 0
		l = not_equal[0][0]
		r = not_equal[0][1]
		diff_set = set()
		for k in range(l, r + 1):
			diff = brr[k] - arr[k]
			if diff < 0:
				print('NO')
				hogaya = 1
				break
			diff_set.add(diff)
		if hogaya == 0:
			if len(diff_set) == 1:
				print('YES')
			else:
				print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == b:
		print('YES')
	else:
		flag1 = 0
		flag2 = 0
		flag3 = 0
		for i in range(n):
			if flag1 == 0:
				if a[i] == b[i]:
					continue
				else:
					flag1 = 1
					if a[i] > b[i]:
						flag2 = 1
						print('NO')
						break
					else:
						d = b[i] - a[i]
						continue
			elif a[i] > b[i]:
				flag2 = 1
				print('NO')
				break
			else:
				c = b[i] - a[i]
				if d == c:
					d = c
					continue
				if d != c and c > 0:
					flag2 = 1
					print('NO')
					break
				if a[i] == b[i]:
					if a[i:] == b[i:]:
						flag3 = 1
						print('YES')
						break
					else:
						flag2 = 1
						print('NO')
						break
		if flag2 == 0 and flag3 == 0:
			print('YES')


def isSimilar(DATAs):
	for DATA in DATAs:
		n = DATA[0]
		A = DATA[1]
		B = DATA[2]
		i = 0
		while i < n:
			if A[i] == B[i]:
				i += 1
			else:
				k = B[i] - A[i]
				if k < 0:
					break
				A[i] += k
				j = i + 1
				while j < n:
					if B[j] - A[j] == k:
						A[j] += k
						j += 1
					elif B[j] - A[j] != 0:
						A[j] += k
						break
					else:
						break
				break
		if A != B:
			print('NO')
		else:
			print('YES')
tests = int(input())
DATAs = []
for test in range(tests):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	DATAs.append([n, A, B])
isSimilar(DATAs)


t = int(input())
for _ in range(t):
	n = int(input())
	alist = [int(i) for i in input().split()]
	blist = [int(i) for i in input().split()]
	clist = [blist[i] - alist[i] for i in range(n)]
	sort = sorted(clist)
	a = sort[-1]
	if sort[0] < 0 or len(set(sort)) > 2 or (0 not in set(sort) and len(set(sort)) > 1):
		print('NO')
		continue
	if a == 0:
		print('YES')
		continue
	clist = clist[clist.index(a):]
	clist.reverse()
	clist = clist[clist.index(a):]
	if clist == [clist[0]] * len(clist):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(y) for y in input().split()]
	arr = [y - x for (x, y) in zip(a, b)]
	one = 0
	zero = False
	if len(set(arr)) > 2:
		print('NO')
	else:
		for i in arr:
			if i < 0:
				print('NO')
				break
			elif i == 0:
				if one != 0:
					zero = True
			elif zero == True:
				print('NO')
				break
			elif one == 0:
				one = i
			elif one != i:
				print('NO')
				break
		else:
			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()]
	l = []
	k = []
	flag = 0
	for i in range(n):
		if a[i] != b[i]:
			if l == []:
				l.append(i)
			elif i == l[-1] + 1:
				l.append(i)
			else:
				print('NO')
				flag = 1
				break
			if k == []:
				k.append(a[i] - b[i])
			if a[i] - b[i] != k[-1] or k[-1] > 0:
				print('NO')
				flag = 1
				break
			else:
				k.append(a[i] - b[i])
	if flag == 0:
		print('YES')


def solve(a, b, n):
	cnt = 0
	d = [0] * (n + 2)
	for i in range(n):
		d[i + 1] = b[i] - a[i]
	for i in range(len(d) - 1):
		if d[i] < 0:
			return False
		if d[i] != d[i + 1]:
			cnt += 1
	return cnt <= 2
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print('YES' if solve(a, b, n) else 'NO')


number_of_tests = int(input())

def sese():
	n = int(input())
	bi = input()
	b = bi.split(' ')
	ai = input()
	a = ai.split(' ')

	def is_possible(no, bo, ao):
		cont1 = True
		t = True
		cou = 0
		k = 10 ** 5
		for i in range(no):
			if int(bo[i]) == int(ao[i]) and int(ao[i - 1]) - int(bo[i - 1]) != k or (int(bo[i]) == int(ao[i]) and i == 0):
				cou += 1
			elif int(bo[i]) < int(ao[i]) and cont1 is True:
				k = int(ao[i]) - int(bo[i])
				cou += 1
				cont1 = False
			elif int(bo[i]) < int(ao[i]) and int(ao[i]) - int(bo[i]) == k and (t is True) and (cont1 is False):
				cou += 1
			elif int(bo[i]) == int(ao[i]) and int(ao[i - 1]) - int(bo[i - 1]) == k and (i != 0):
				t = False
				cou += 1
			else:
				break
		if cou == n:
			return 'YES'
		else:
			return 'NO'
	if is_possible(n, b, a) == 'NO':
		return 'NO'
	else:
		return 'YES'
ans = []
for p in range(number_of_tests):
	ans = ans + [sese()]
for anss in ans:
	print(anss)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	for i in range(n):
		if a[i] != b[i] and d == 0 and (a[i] < b[i]):
			k = a[i] - b[i]
			d = 1
		elif a[i] != b[i] and d == 1 and (a[i] < b[i]):
			if a[i] - b[i] != k:
				print('NO')
				d = 2
				break
		elif a[i] == b[i]:
			if d == 0:
				pass
			else:
				d = 3
		elif a[i] != b[i] and d == 3:
			print('NO')
			d = 2
			break
		elif a[i] > b[i]:
			print('NO')
			d = 2
			break
	if d != 2:
		print('YES')


tt = int(input())
for t in range(tt):
	_ = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	c = []
	diff = None
	zeroed = False
	success = True
	for i in range(len(a)):
		d = a[i] - b[i]
		if diff is None and d != 0:
			diff = d
		elif d != 0 and d != diff:
			success = False
			break
		elif d == 0 and diff is not None:
			zeroed = True
		elif d == diff and zeroed:
			success = False
			break
	if success and (diff is None or diff < 0):
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	d = -9999
	for i in range(n):
		nd = B[i] - A[i]
		if nd == d or (nd == 0 and d == -9999):
			continue
		if nd < 0:
			d = -10000
			break
		if d == -9999:
			d = nd
		elif nd == 0:
			d = 0
		else:
			d = -10000
			break
	print('YES' if d >= -9999 else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	count = 0
	choice = 1
	for i in range(n):
		if a[i] > b[i]:
			print('NO')
			choice = 0
			break
		elif a[i] < b[i]:
			if count == 0:
				count += 1
				choice = 1
				diff = b[i] - a[i]
			elif count == 2:
				choice = 0
				print('NO')
				break
			elif b[i] - a[i] != diff:
				print('NO')
				choice = 0
				break
		elif count == 1:
			count += 1
	if choice == 1:
		print('YES')


t = int(input())
for cc in range(t):
	chk = 0
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	x = 0
	ch = 1
	while x < n:
		if a[x] != b[x]:
			k = b[x] - a[x]
			if k < 0:
				ch = 0
				break
			if chk == 1:
				ch = 0
				break
			chk = 1
			while b[x] - a[x] == k:
				x = x + 1
				if x >= n:
					break
		elif a[x] == b[x]:
			x = x + 1
	if ch == 0:
		print('NO')
	else:
		print('YES')


T = int(input())
for t in range(T):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
		continue
	ind = 0
	ind2 = 0
	for i in range(N):
		if a[i] != b[i]:
			ind = i
			break
	for i in range(N):
		if a[-1 - i] != b[-1 - i]:
			ind2 = i
			break
	temp = a[ind] - b[ind]
	if temp > 0:
		print('NO')
		continue
	flag = 0
	for i in range(ind, N - ind2):
		if temp != a[i] - b[i]:
			print('NO')
			flag = 1
			break
	if flag == 0:
		print('YES')


def f():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	co = 0
	flag = 0
	l = []
	for i in range(0, n):
		if b[i] - a[i] < 0:
			return 'NO'
		l.append(b[i] - a[i])
	for i in range(1, n):
		if l[i] != l[i - 1]:
			if l[i] != 0 and l[i - 1] != 0:
				return 'NO'
			co += 1
			if co == 1:
				if l[i - 1] != 0:
					flag = 1
			if flag == 1 and co > 1:
				return 'NO'
			if co > 2:
				return 'NO'
	return 'YES'
for i in range(int(input())):
	print(f())


ints = lambda : [int(x) for x in input().split()]

def main():
	(ntc,) = ints()
	for tc in range(ntc):
		((n,), a, b) = (ints(), ints(), ints())
		d = [y - x for (x, y) in zip(a, b)]
		i = next((j for j in range(n) if d[j] != 0), n)
		if i < n and d[i] > 0:
			i = next((j for j in range(i, n) if d[j] != d[i]), n)
			i = next((j for j in range(i, n) if d[j] != 0), n)
		print('YES' if i == n else 'NO')
main()


T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		a[i] = b[i] - a[i]
	indL = 0
	while indL < n and a[indL] == 0:
		indL += 1
	indR = n - 1
	while indR >= 0 and a[indR] == 0:
		indR -= 1
	if indL > indR:
		print('YES')
	elif max(a[indL:indR + 1]) == min(a[indL:indR + 1]) and a[indL] >= 0:
		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()))
	l = []
	r = []
	temp = False
	valid = True
	for i in range(n):
		if a[i] != b[i]:
			if len(l) == 0:
				temp = True
			if temp == True:
				l.append(a[i])
				r.append(b[i])
			else:
				valid = False
				break
		if a[i] == b[i]:
			temp = False
	if len(l) == 0:
		print('YES')
		continue
	if valid and (not abs(sum(l) - sum(r)) % len(l)):
		k = abs(sum(l) - sum(r)) / len(l)
		for j in range(len(l)):
			l[j] += k
		if l == r:
			print('YES')
		else:
			print('NO')
	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()))
	c = []
	p = []
	if a == b:
		print('YES')
	else:
		for i in range(len(a)):
			c.append(b[i] - a[i])
			if b[i] - a[i] > 0:
				p.append(1)
			else:
				p.append(0)
		flag = 0
		for i in range(len(c)):
			if c[i] < 0:
				flag += 1
		if flag > 0:
			print('NO')
		else:
			try:
				o = p.index(1)
				p.reverse()
				l = n - p.index(1) - 1
				p.reverse()
				r = p[o:l + 1]
				if r.count(0) == 0:
					flag1 = 0
					for i in range(o, l + 1):
						if c[i] != c[l]:
							flag1 += 1
					if flag1 == 0:
						print('YES')
					else:
						print('NO')
				else:
					print('NO')
			except:
				flag2 = 0
				for i in range(len(c)):
					if c[i] != c[o]:
						flag2 += 1
				if flag2 == 0:
					print('YES')
				else:
					print('NO')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	n = l()[0]
	A = [0] + l() + [0]
	B = [0] + l() + [0]
	d = 10 ** 5
	ans = 'YES'
	for i in range(n + 2):
		if A[i] == B[i] and d == 10 ** 5:
			continue
		elif A[i] != B[i] and d == 10 ** 5:
			d = A[i] - B[i]
			if d > 0:
				ans = 'NO'
				break
		elif A[i] != B[i] and d != 10 ** 5:
			if B[i] + d != A[i]:
				ans = 'NO'
				break
		else:
			if A[i:] != B[i:]:
				ans = 'NO'
			break
	print(ans)


def compare(a, b):
	n = len(a)
	for i in range(n):
		if a[i] == b[i]:
			continue
		else:
			k = b[i] - a[i]
			for j in range(i, n):
				if b[j] - a[j] != k:
					for k in range(j, n):
						if a[k] == b[k]:
							return 'YES'
						else:
							return 'NO'

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


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


t = int(input())
S = [1] * t
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	R = [0]
	for j in range(n):
		if B[j] < A[j]:
			S[i] = 0
			break
		elif B[j] - A[j] != R[-1]:
			R.append(B[j] - A[j])
	if len(R) > 3 or (len(R) == 3 and R[2] != 0):
		S[i] = 0
for k in range(t):
	if S[k] == 1:
		print('YES')
	else:
		print('NO')


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def check(x):
	(s, e) = (None, None)
	for i in range(len(x)):
		if x[i] > 0:
			s = i
			break
	for i in range(len(x) - 1, -1, -1):
		if x[i] > 0:
			e = i
			break
	if x[s:e + 1].count(x[s]) == e + 1 - s:
		print('YES')
	else:
		print('NO')

def solve():
	T = int(input())
	for _ in range(T):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		diff = []
		for i in range(n):
			if b[i] - a[i] >= 0:
				diff.append(b[i] - a[i])
			else:
				diff.append('neg')
		if 'neg' in diff:
			print('NO')
		elif len(set(diff)) == 1:
			print('YES')
		else:
			check(diff)
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
solve()


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list((int(x) for x in input().split(' ')))
	l2 = list((int(x) for x in input().split(' ')))
	l = None
	r = None
	k = None
	for i in range(len(l1)):
		if l1[i] == l2[i]:
			if l != None:
				r = i
			continue
		elif l == None:
			l = i
			k = l1[i] - l2[i]
			if k > 0:
				print('NO')
				break
			continue
		elif l1[i] - l2[i] != k:
			print('NO')
			break
		elif r != None:
			print('NO')
			break
	else:
		print('YES')


n = int(input())
for _ in range(n):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
		continue
	dif = []
	dif_ind = []
	for (i, (j, k)) in enumerate(zip(a, b)):
		if j != k:
			dif.append(j - k)
			dif_ind.append(i)
	ans = 'YES'
	if len(set(dif)) != 1:
		ans = 'NO'
	if not all((d < 0 for d in dif)):
		ans = 'NO'
	for i in range(len(dif_ind) - 1):
		if dif_ind[i] + 1 != dif_ind[i + 1]:
			ans = 'NO'
	print(ans)


def makeEqual(arr1, arr2):
	if len(arr1) == 1:
		return arr1[0] <= arr2[0]
	(r, l, k) = (0, 0, 0)
	while l < len(arr1):
		if arr1[l] != arr2[l]:
			break
		l += 1
	if l == len(arr1):
		return True
	k = arr2[l] - arr1[l]
	if k < 0:
		return False
	r = l
	while r < len(arr1):
		if arr1[r] + k != arr2[r]:
			break
		r += 1
	i = l
	while i < r:
		if arr1[i] + k != arr2[i]:
			return False
		i += 1
	i = r
	while i < len(arr1):
		if arr1[i] != arr2[i]:
			return False
		i += 1
	return True
tc = int(input())
for etc in range(tc):
	lr = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	print('YES' if makeEqual(arr1, arr2) else 'NO')


for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	l1 = []
	f = 1
	for i in range(x):
		l1.append(k[i] - l[i])
		if k[i] - l[i] < 0:
			f = 0
			print('NO')
			break
	if f == 0:
		continue
	t = []
	t1 = []
	for i in range(0, x):
		if l1[i] > 0:
			t.append(i)
			t1.append(l1[i])
	if len(set(t1)) > 1:
		print('NO')
		continue
	f = 1
	for i in range(len(t) - 1):
		if t[i] + 1 != t[i + 1]:
			f = 0
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


import sys
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	if a == b:
		print('YES')
		continue
	j = 0
	while j < n:
		if a[j] == b[j]:
			j = j + 1
		else:
			break
	k = n - 1
	while k > 0:
		if a[k] == b[k]:
			k = k - 1
		else:
			break
	q = set()
	for v in range(j, k + 1):
		q.add(b[v] - a[v])
	if len(q) == 1 and q.pop() > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	first = 1
	done = 0
	ruined = 0
	for x in range(len(l1)):
		if l1[x] != l2[x]:
			if not first and done:
				ruined = 1
				break
			if first:
				temp = l1[x] - l2[x]
				if temp > 0:
					ruined = 1
					break
				first = 0
			elif l1[x] - l2[x] != temp:
				ruined = 1
				break
		elif not first:
			done = 1
	if ruined:
		print('NO')
	else:
		print('YES')


def fun(n):
	tag = True
	for l in range(n):
		if a[l] != b[l]:
			tag = False
			d = b[l] - a[l]
			if d < 0:
				print('NO')
				return
			else:
				break
	if tag:
		print('YES')
		return
	for r in range(n - 1, -1, -1):
		if a[r] != b[r]:
			break
	for k in range(l, r + 1):
		if b[k] - a[k] != d:
			print('NO')
			return
	print('YES')
	return
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	fun(n)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = []
	for i in range(n):
		ans.append(a[i] - b[i])
	aa = list(set(ans))
	k = 0
	if len(aa) > 2:
		print('NO')
		continue
	if len(aa) == 2:
		if aa[0] != 0 and aa[1] != 0:
			print('NO')
			continue
	if k == 0:
		for i in aa:
			if i > 0:
				print('NO')
				k += 1
				break
	if k == 0:
		i = 1
		t = 0
		while i < n - 1:
			if ans[i] == 0:
				if ans[i - 1] != 0 and ans[i + 1] != 0:
					print('NO')
					t = 10
			i += 1
		if t != 10:
			print('YES')


from operator import itemgetter
from math import sqrt
t = int(input())

def solve(a, b):
	k = 0
	flag = False
	flag2 = False
	ll = len(a)
	for i in range(ll):
		if not flag and (not flag2):
			if b[i] != a[i]:
				flag = True
				k = b[i] - a[i]
				if k < 0:
					return 'NO'
		elif flag and (not flag2):
			if b[i] - k != a[i] and b[i] != a[i]:
				return 'NO'
			elif b[i] == a[i]:
				flag2 = True
		elif flag2:
			if b[i] != a[i]:
				return 'NO'
	return 'YES'
for j in range(t):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b))


from sys import stdin, stdout
import collections

def test():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(l, r) = (0, n - 1)
	while l <= r and (a[l] == b[l] or a[r] == b[r]):
		if a[l] == b[l]:
			l += 1
		if a[r] == b[r]:
			r -= 1
	if l > r:
		print('YES')
	else:
		d = b[l] - a[l]
		if d < 0:
			print('NO')
			return
		for i in range(l, r + 1):
			if b[i] != a[i] + d:
				print('NO')
				return
		print('YES')

def main():
	t = int(input())
	for _ in range(t):
		test()
main()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	j = 0
	for i in range(n):
		if a[i] != b[i]:
			j = i
			break
	c = 0
	ll = 0
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			ll = i
			break
	if a[j] > b[j]:
		c = -1
	k = b[j] - a[j]
	cnt = 0
	for i in range(j, min(ll + 1, n)):
		a[i] += k
		if a[i] != b[i]:
			c = -1
	if c == -1:
		print('NO')
	else:
		print('YES')
	t -= 1


def up(a, b):
	i = 0
	while i < len(a):
		if b[i] - a[i] == 0:
			pass
		elif b[i] - a[i] < 0:
			return False
		else:
			k = b[i] - a[i]
			i += 1
			break
		i += 1
	while i < len(a):
		if b[i] - a[i] == k:
			pass
		elif b[i] - a[i] == 0:
			i += 1
			break
		else:
			return False
		i += 1
	while i < len(a):
		if b[i] - a[i] == 0:
			pass
		else:
			return False
		i += 1
	return True
t = int(input())
for i in range(t):
	z = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if up(a, b):
		print('YES')
	else:
		print('NO')


case = int(input())
for i in range(case):
	key = True
	l = int(input())
	data = input()
	data = data.split()
	data = [int(x) for x in data]
	data2 = input()
	data2 = data2.split()
	data2 = [int(x) for x in data2]
	mal = []
	for j in range(l):
		mal.append(data2[j] - data[j])
	for j in range(l):
		if mal[0] != 0:
			break
		else:
			mal.pop(0)
	x = len(mal)
	for j in range(x):
		if mal[-1] != 0:
			break
		else:
			mal.pop(-1)
	if len(mal) == 0:
		print('YES')
		continue
	if mal.count(0) > 0:
		print('NO')
		continue
	yo = mal[0]
	for i in mal:
		if i != yo or i < 0:
			print('NO')
			key = False
			break
	if key:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	result = True
	k = 0
	m = -1
	for i in range(n):
		if a[i] != b[i]:
			if b[i] < a[i]:
				result = False
				break
			k = b[i] - a[i]
			m = i
			break
	for j in range(m, n):
		if a[j] == b[j]:
			break
		a[j] += k
	for j in range(n):
		if a[j] != b[j]:
			result = False
			break
	if result:
		print('YES')
	else:
		print('NO')


def calculateAnswer(a, b):
	difference = None
	first_operation_ended = False
	for (item_a, item_b) in zip(a, b):
		if item_a > item_b:
			return 'NO'
		if item_a == item_b:
			if difference:
				first_operation_ended = True
				difference = None
		if item_a != item_b:
			if first_operation_ended:
				return 'NO'
			difference_new = item_b - item_a
			if difference:
				if difference != difference_new:
					return 'NO'
			difference = item_b - item_a
	return 'YES'

def testAnswer():
	test_case_count = int(input())
	for i in range(test_case_count):
		input()
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print(calculateAnswer(a, b))
testAnswer()


t = int(input())
for i in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [0] * n
	s = 0
	for j in range(0, n):
		c[j] = b[j] - a[j]
		if c[j] >= 0:
			s += 1
	if s < n:
		print('NO')
	elif len(set(c)) >= 3:
		print('NO')
	elif len(set(c)) == 1:
		print('YES')
	elif 0 not in c:
		print('NO')
	else:
		d = []
		for j in range(0, n):
			if c[j] != 0:
				d.append(j)
		if max(d) - min(d) == c.count(max(c)) - 1:
			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()))
	C = []
	for (a, b) in zip(A, B):
		C.append(b - a)
	cur = C[0]
	X = []
	for i in range(n):
		if C[i] == cur:
			continue
		else:
			if cur != 0:
				X.append(cur)
			cur = C[i]
	else:
		if cur != 0:
			X.append(cur)
	if not X:
		print('YES')
	elif len(X) == 1 and X[0] > 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l = []
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1 and a[0] <= b[0]:
		print('YES')
	elif n == 1:
		print('NO')
	elif a == b:
		print('YES')
	else:
		for i in range(n):
			if b[i] - a[i] > 0:
				l.append(i)
		if len(l) == 0:
			print('NO')
		else:
			q = b[l[0]] - a[l[0]]
			for i in range(l[0], l[-1] + 1):
				a[i] += q
			if a == b:
				print('YES')
			else:
				print('NO')


import itertools

def main():
	n = int(input())
	for i in range(n):
		s = input()
		data1 = [int(v) for v in input().split()]
		data2 = [int(v) for v in input().split()]
		res = []
		for (i, v) in enumerate(data1):
			res.append(data2[i] - v)
		if any([v < 0 for v in res]):
			print('NO')
			continue
		s = 0
		for (i, v) in enumerate(res):
			if v != 0:
				s = i
				break
		f = 0
		for (i, v) in enumerate(reversed(res)):
			if v != 0:
				f = i
				break
		if len(set(res[s:len(res) - f])) <= 1:
			print('YES')
		else:
			print('NO')
main()


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	n = int(input())
	a = list_input()
	b = list_input()
	i = 0
	flag = False
	while i < n:
		if a[i] != b[i]:
			if flag:
				print('NO')
				return
			flag = True
			prev = b[i] - a[i]
			if prev < 0:
				print('NO')
				return
			i += 1
			while i < n and a[i] != b[i]:
				if prev != b[i] - a[i]:
					print('NO')
					return
				i += 1
		else:
			i += 1
	print('YES')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [0]
	c = 0
	for i in range(n):
		l.append(b[i] - a[i])
	l.append(0)
	for i in range(len(l) - 1):
		if l[i] != l[i + 1]:
			c += 1
	x = min(l)
	if x < 0:
		print('NO')
	elif l[0] < 0:
		print('NO')
	elif l[0] >= 0:
		if c <= 2:
			print('YES')
		else:
			print('NO')


def con():
	t = int(input())
	for i in range(t):
		verif = 1
		n = int(input())
		ch1 = input()
		a = [int(j) for j in ch1.split()]
		ch2 = input()
		b = [int(j) for j in ch2.split()]
		if ch1 == ch2:
			print('YES')
			continue
		k = 0
		B = True
		while B == True and k < n:
			if verif == 0:
				break
			if a[k] > b[k]:
				B = False
				break
			elif a[k] < b[k]:
				tmp = b[k] - a[k]
				v = k
				B1 = True
				while B1 == True:
					if b[v] == tmp + a[v]:
						v = v + 1
						if v == n:
							verif = 0
							break
					else:
						k = v
						B1 = False
						for l in range(k, n):
							if a[l] == b[l]:
								continue
							else:
								B = False
			else:
				k = k + 1
		if B == True:
			print('YES')
		else:
			print('NO')
con()


test_case = int(input())
for i in range(test_case):
	size = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	if a == b:
		print('YES')
	else:
		v = []
		for i in range(size):
			if a[i] == b[i]:
				continue
			else:
				v.append(i)
		size = len(v)
		for i in range(size):
			try:
				if v[i + 1] - v[i] != 1:
					ans = 1
					break
			except:
				break
		if ans == 1:
			print('NO')
		else:
			index = v[0]
			k = b[index] - a[index]
			if k < 0:
				print('NO')
			else:
				for i in v:
					a[i] += k
				if a == b:
					print('YES')
				else:
					print('NO')


from itertools import groupby
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [a[i] - b[i] for i in range(n)]
	d = [[i, list(j)] for (i, j) in groupby(c, key=lambda x: x == 0) if i == False]
	if len(d) >= 2:
		print('NO')
	elif len(d) == 0:
		print('YES')
	else:
		l = len(d[0][1])
		for i in range(l):
			if d[0][1][i] != d[0][1][0]:
				print('NO')
				break
		else:
			if d[0][1][i] > 0:
				print('NO')
			else:
				print('YES')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	elif sum(a) > sum(b):
		print('NO')
	else:
		x = []
		y = []
		for i in range(n):
			if a[i] != b[i]:
				x.append(i)
				y.append(b[i] - a[i])
		q = True
		for i in range(len(x) - 1):
			x[i] = x[i + 1] - x[i]
			if x[i] > 1:
				print('NO')
				q = False
				break
		if q == True:
			ans = 'YES'
			for i in range(len(y)):
				if y[0] != y[i]:
					ans = 'NO'
					break
			print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = [b[i] - a[i] for i in range(n)]
	diff = set(d)
	diff = list(diff)
	ok = True
	for i in diff:
		if i < 0:
			ok = False
	if ok == True:
		if len(diff) > 2:
			print('NO')
		elif len(diff) == 1:
			ok = False
			kk = True
			i = 0
			while i < n:
				if d[i] is not 0:
					if ok is False:
						ok = True
						while i < n:
							if d[i] is not 0:
								i += 1
							else:
								break
					else:
						kk = False
						break
				else:
					i += 1
			if kk:
				print('YES')
			else:
				print('NO')
		elif 0 in diff:
			ok = False
			kk = True
			i = 0
			while i < n:
				if d[i] is not 0:
					if ok is False:
						ok = True
						while i < n:
							if d[i] is not 0:
								i += 1
							else:
								break
					else:
						kk = False
						break
				else:
					i += 1
			if kk:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	b = li()
	i = 0
	while i < n and b[i] - a[i] == 0:
		i += 1
	if i == n:
		print('YES')
		continue
	else:
		d = b[i] - a[i]
		if d < 0:
			print('NO')
			continue
		else:
			while i < n and b[i] - a[i] == d:
				i += 1
			f = True
			for j in range(i, n):
				if b[j] - a[j] != 0:
					print('NO')
					f = False
					break
			if f:
				print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	una = []
	unb = []
	s = False
	d = False
	ok = True
	for i in range(n):
		if a[i] == b[i] and s:
			d = True
		if d and a[i] != b[i]:
			ok = False
			break
		if a[i] != b[i] and (not s):
			s = True
		if s and (not d):
			una.append(a[i])
			unb.append(b[i])
	if ok:
		if len(una) == 0:
			print('YES')
		else:
			diff = una[0] - unb[0]
			rok = True
			for i in range(len(una)):
				if una[i] - unb[i] != diff or diff > 0:
					rok = False
					break
			if rok:
				print('YES')
			else:
				print('NO')
	else:
		print('NO')


t = int(input())
for kekes in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [B[i] - A[i] for i in range(n)]
	if len(set(C)) > 2:
		print('NO')
	else:
		j = n - 1
		while j > 0 and C[j] == 0:
			j -= 1
		i = 0
		while i < n - 1 and C[i] == 0:
			i += 1
		if A == B or (len(set(C[i:j + 1])) == 1 and max(C) > 0):
			print('YES')
		else:
			print('NO')


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	flag1 = 0
	for i in range(n):
		if flag == 0:
			if a[i] == b[i]:
				continue
			if a[i] != b[i]:
				flag = 1
				k = a[i] - b[i]
				if k >= 0:
					print('NO')
					flag1 = 1
					break
				continue
		if flag == 1:
			if a[i] - b[i] == k:
				continue
			if a[i] == b[i]:
				flag = 2
				continue
			if a[i] - b[i] != k:
				flag1 = 1
				print('NO')
				break
		if flag == 2:
			if a[i] == b[i]:
				continue
			else:
				flag1 = 1
				print('NO')
				break
	if flag1 == 0:
		print('YES')


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


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	if l == p:
		print('YES')
		continue
	diff = -1
	start = False
	end = False
	ok = True
	for i in range(len(l)):
		if l[i] > p[i]:
			ok = False
		di = p[i] - l[i]
		if di > 0 and end:
			ok = False
		if di > 0 and (not start):
			start = True
			diff = di
		elif di > 0 and start:
			if di != diff:
				ok = False
		elif di == 0 and start:
			end = True
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	x = []
	a = []
	c = 0
	x.append(0)
	for i in range(n):
		x.append(m[i] - l[i])
	x.append(0)
	for i in range(0, len(x) - 1):
		if x[i] != x[i + 1]:
			c = c + 1
	if c <= 2 and sorted(x)[0] >= 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()))
	l = []
	r = 0
	while r < n:
		l.append(b[r] - a[r])
		r += 1
	m = list(set(l))
	m.sort()
	if m == [0]:
		print('YES')
	elif len(m) == 1:
		if m[0] > 0:
			print('YES')
		else:
			print('NO')
	elif len(m) > 2:
		print('NO')
	elif m[0] != 0:
		print('NO')
	else:
		(f, e) = (0, 0)
		for i in range(len(l)):
			if l[i] != 0:
				f = i
				break
		for i in range(len(l)):
			if l[i] != 0:
				e = i
		t = 0
		for i in range(f, e + 1):
			if l[i] == 0:
				print('NO')
				t = 1
		if t == 0:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dis = []
	for i in range(n):
		dis.append(a[i] - b[i])
	prev = 10 ** 10
	(f, cnt) = (False, 0)
	for i in dis:
		if i > 0:
			f = True
			break
		elif i < 0:
			if prev == 10 ** 10:
				prev = i
			elif i != prev or cnt == 1:
				f = True
				break
		elif prev != 10 ** 10 and i == 0:
			cnt = 1
	if f == True:
		print('NO')
	else:
		print('YES')


def one_rise(a, b):
	diff = 0
	diff_changed = False
	for (el_a, el_b) in zip(a, b):
		new_diff = el_b - el_a
		if new_diff != diff:
			if diff_changed and new_diff != 0 or new_diff < 0:
				return False
			else:
				diff = new_diff
				diff_changed = True
	return True

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if one_rise(a, b):
			print('YES')
		else:
			print('NO')
main()


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	c = 0
	q = []
	f = 0
	y = []
	for i in range(m):
		t = p[i] - l[i]
		if t != 0:
			q.append(t)
			y.append(i)
			c += 1
			if c > 1:
				if q[-2] != q[-1] or y[-1] - 1 != y[-2]:
					print('NO')
					f += 1
					break
		if t < 0:
			f += 1
			print('NO')
			break
	if f == 0:
		print('YES')


n = int(input())
for _ in range(n):
	k = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	w = []
	for i in range(k):
		c = l1[i] - l2[i]
		w.append(c)
	l3 = []
	l4 = []
	q = 0
	for i in range(k):
		if w[i] != 0:
			if w[i] > 0:
				q += 1
				break
			else:
				l3.append(i)
				l4.append(w[i])
	if q == 1:
		print('NO')
	elif len(l4) < 2:
		print('YES')
	else:
		c = l4[0]
		for i in range(1, len(l3)):
			if l3[i] - l3[i - 1] != 1:
				q += 1
				break
			elif l4[i] != c:
				q += 1
				break
		if q == 0:
			print('YES')
		else:
			print('NO')


t = int(input())
for case in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	deltas = [0]
	delta_types = set([0])
	for i in range(len(arr2)):
		delta = arr2[i] - arr1[i]
		deltas.append(delta)
		delta_types.add(delta)
	if len(delta_types) > 2:
		print('NO')
	elif len(delta_types) == 1:
		print('YES')
	else:
		min_delta = min(delta_types)
		if min_delta < 0:
			print('NO')
		else:
			num_change = 0
			for i in range(len(deltas) - 1):
				if deltas[i] == 0 and deltas[i + 1] != 0:
					num_change += 1
			if num_change == 1:
				print('YES')
			else:
				print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a_list = input().split(' ')
	b_list = input().split(' ')
	prev_diff = 0
	current_diff = 0
	diff_found = 0
	result = ''
	if n == 1:
		if b_list[0] >= a_list[0]:
			result = 'YES'
		else:
			result = 'NO'
	else:
		for j in range(n):
			current_diff = int(b_list[j]) - int(a_list[j])
			if current_diff < 0:
				result = 'NO'
			elif diff_found == 0:
				if current_diff != 0:
					prev_diff = current_diff
					diff_found = 1
			elif current_diff == 0:
				prev_diff = current_diff
			else:
				if prev_diff == 0:
					result = 'NO'
				if prev_diff != 0 and prev_diff != current_diff:
					result = 'NO'
	if result == '':
		result = 'YES'
	print(result)


from sys import stdin
t = int(stdin.readline().rstrip())
while t > 0:
	n = int(stdin.readline().rstrip())
	l1 = list(map(int, stdin.readline().split()))
	l2 = list(map(int, stdin.readline().split()))
	f = 0
	se = set()
	c = 0
	k = 0
	for i in range(n):
		if l1[i] == l2[i]:
			k = 1
		elif l1[i] > l2[i]:
			f = 1
			break
		else:
			if k == 1 or i == 0:
				k = 0
				c += 1
			se.add(l2[i] - l1[i])
	if f == 1:
		print('NO')
	elif len(se) > 1:
		print('NO')
	elif c > 1:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	diff = [b[i] - a[i] for i in range(n)]
	has_negative = any([x < 0 for x in diff])
	if has_negative:
		print('NO')
	else:
		cnt = 0
		diff = [0] + diff + [0]
		for i in range(len(diff) - 1):
			if diff[i] != diff[i + 1]:
				cnt += 1
		if cnt <= 2:
			print('YES')
		else:
			print('NO')


t = int(input())
n = []
a = []
b = []
for i in range(t):
	n.append(int(input()))
	a.append(list(map(int, input().split())))
	b.append(list(map(int, input().split())))
for i in range(t):
	c = [a[i][k] - b[i][k] for k in range(len(a[i]))]
	test = True
	L = [c[0]]
	prec = c[0]
	for j in range(len(c)):
		if len(L) == 3 or c[j] > 0:
			test = False
			break
		elif c[j] not in L:
			L.append(c[j])
		elif (c[j] in L and c[j] != prec) and c[j] != 0:
			test = False
			break
		prec = c[j]
	if not test or (len(L) == 2 and 0 not in L) or len(L) == 3:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.buffer.readline
import os
from math import *
import copy
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	ans = []
	for i in range(n):
		ans.append(brr[i] - arr[i])
	bns = copy.deepcopy(ans)
	bns.sort()
	if bns[0] < 0:
		print('NO')
	else:
		ip = 0
		fp = 0
		for i in range(n):
			if ans[i] > 0:
				ip = i
				break
		for i in range(n - 1, -1, -1):
			if ans[i] > 0:
				fp = i
				break
		ans = ans[ip:fp + 1]
		if len(set(ans)) == 1:
			print('YES')
		else:
			print('NO')


def check_greater(arrayA, arrayB):
	for i in range(len(arrayA)):
		if int(arrayA[i]) > int(arrayB[i]):
			return False
	return True

def check(arrayA, arrayB):
	for i in range(len(arrayA)):
		if arrayA[i] != arrayB[i]:
			return False
	return True

def imposible(arrayA, arrayB):
	checker = []
	for i in range(len(arrayA)):
		if int(arrayA[i]) != int(arrayB[i]):
			checker.append(i)
	for i in range(len(checker)):
		if i + 1 < len(checker):
			if checker[i] + 1 != checker[i + 1]:
				return True
	return False

def single_push():
	cases = int(input())
	length = []
	arrayA = []
	arrayB = []
	for i in range(cases):
		length.append(int(input()))
		arrayA.append(input().split())
		arrayB.append(input().split())
	for i in range(len(arrayA)):
		if check(arrayA[i], arrayB[i]):
			print('YES')
		elif not check_greater(arrayA[i], arrayB[i]):
			print('NO')
		elif imposible(arrayA[i], arrayB[i]):
			print('NO')
		else:
			dic = {}
			change = True
			for j in range(len(arrayA[i])):
				if int(arrayB[i][j]) - int(arrayA[i][j]) not in dic:
					dic[int(arrayB[i][j]) - int(arrayA[i][j])] = 1
					if len(dic) > 2:
						print('NO')
						change = False
						break
			if change:
				if len(dic) == 2:
					if 0 in dic:
						print('YES')
					else:
						print('NO')
				elif len(dic) < 2:
					print('YES')
single_push()


Ans = []
for j in range(int(input())):
	l = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	x = 0
	m = 0
	for i in range(l):
		if x == 0:
			if A[i] != B[i]:
				x = A[i] - B[i]
				if x > 0:
					m += 10
				m += 1
		elif x != A[i] - B[i]:
			if A[i] == B[i]:
				x = 0
			else:
				m = 10
	if m > 1:
		Ans.append(False)
	else:
		Ans.append(True)
for y in Ans:
	if y:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	b = map(int, input().split())
	cur_diff = 0
	started = ended = False
	possible = True
	for (x, y) in zip(a, b):
		if x != y and started == ended == True:
			possible = False
			break
		if x != y:
			if cur_diff == 0:
				cur_diff = y - x
				started = True
			if y - x != cur_diff:
				possible = False
				break
		elif x == y and started == True:
			ended = True
	if possible and cur_diff >= 0:
		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()]
	diff = None
	f = True
	f1 = False
	f2 = False
	for j in range(len(a)):
		if a[j] > b[j]:
			f = False
			break
		elif a[j] != b[j]:
			if f1:
				f = False
				break
			elif not diff:
				diff = b[j] - a[j]
				f2 = True
			elif b[j] - a[j] != diff:
				f = False
				break
		else:
			if f2:
				f1 = True
			diff = None
	if f:
		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()))
	diff = []
	for i in range(n):
		diff.append(b[i] - a[i])
	k = list(set(diff))
	if min(k) < 0:
		print('NO')
	elif len(k) == 1:
		print('YES')
	elif len(k) > 2:
		print('NO')
	elif len(k) == 2 and diff.count(0) == 0:
		print('NO')
	else:
		for i in k:
			if i != 0:
				x = i
		if n - diff[::-1].index(x) - diff.index(x) == diff.count(x):
			print('YES')
		else:
			print('NO')


mod = 10 ** 9 + 7
INF = float('inf')

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

def readTuples():
	return tuple(map(int, input().split()))

def I():
	return int(input())
q = I()
for _ in range(q):
	n = I()
	A = readInts()
	B = readInts()
	nya = []
	sw = False
	end = False
	ok = True
	for i in range(n):
		if A[i] == B[i]:
			if sw and ok:
				ok = False
			else:
				pass
		elif ok:
			sw = True
			if B[i] - A[i] < 0:
				print('NO')
				end = True
				break
			if len(nya) == 0:
				nya.append(B[i] - A[i])
			elif nya[0] == B[i] - A[i]:
				pass
			else:
				print('NO')
				end = True
				break
		elif B[i] - A[i] != 0:
			print('NO')
			end = True
			break
	if end:
		pass
	else:
		print('YES')


for _ in range(int(input())):
	l = []
	c = 0
	k = 0
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	l.append(0)
	for i in range(n):
		l.append(B[i] - A[i])
	l.append(0)
	for j in range(0, len(l) - 1):
		if l[j] != l[j + 1]:
			c += 1
	print('YES' if c <= 2 and sorted(l)[0] >= 0 else 'NO')


T = int(input())
ans = 0
while T > 0:
	T -= 1
	N = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	state = False
	diff = 0
	possible = True
	for i in range(N):
		if state == 0:
			if arr1[i] != arr2[i]:
				state = 1
				diff = arr2[i] - arr1[i]
				if diff < 0:
					possible = False
					break
		elif state == 1:
			if arr1[i] == arr2[i]:
				state = 2
			elif arr2[i] - arr1[i] != diff:
				possible = False
				break
		elif arr1[i] != arr2[i]:
			possible = False
			break
	if possible:
		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()))
	c = [b[i] - a[i] for i in range(n)]
	c.insert(0, 0)
	c.append(0)
	cont = False
	for i in c:
		if i < 0:
			print('NO')
			cont = True
			break
	if cont:
		cont = False
		continue
	ct = 0
	for i in range(n + 1):
		if c[i] != c[i + 1]:
			ct += 1
	if ct <= 2:
		print('YES')
	else:
		print('NO')


n = int(input())
res = []
for i in range(3 * n):
	res += [input().split()]
for i in range(0, 3 * n, 3):
	(a, b, m, z) = ([int(y) for y in res[i + 1]], [int(y) for y in res[i + 2]], [], [])
	for x in range(int(res[i][0])):
		if a[x] > b[x]:
			print('NO')
			z = [i for i in range(1001)]
			break
		elif a[x] == b[x]:
			pass
		elif a[x] < b[x]:
			z.append(b[x] - a[x])
			m.append(x)
	if len(set(z)) == 0:
		print('YES')
	elif len(set(z)) == 1:
		if m[-1] - m[0] == len(m) - 1:
			print('YES')
		else:
			print('NO')
	elif len(set(z)) == 1001:
		pass
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	tmp = -1
	st = -1
	c = [0] * n
	for i in range(n):
		c[i] = b[i] - a[i]
	otf = True
	flag = True
	otfi = -1
	i = 0
	while i < n:
		if c[i] < 0:
			flag = False
			break
		elif c[i] > 0:
			if otf:
				otf = False
				tmp = c[i]
				while i < n:
					if c[i] == tmp:
						i += 1
					else:
						break
			else:
				flag = False
				break
		else:
			i += 1
	if flag:
		print('YES')
	else:
		print('NO')


test = input()
for i in range(int(test)):
	n = int(input())
	a = input().split(' ')
	b = input().split(' ')
	L = []
	for i in range(n):
		if int(a[i]) == int(b[i]):
			continue
		else:
			L.append(i)
	if len(L) == 0:
		print('YES')
	else:
		p = len(L)
		n1 = int(L[0])
		d = int(a[n1]) - int(b[n1])
		if d > 0:
			print('NO')
		else:
			for i in range(n1, n1 + len(L)):
				b[i] = str(int(b[i]) + int(d))
			h1 = 'YES'
			for i in range(n):
				if int(a[i]) == int(b[i]):
					continue
				else:
					h1 = 'NO'
					break
			print(h1)


t = int(input())
g = []
for i in range(t):
	k = 0
	l = 0
	r = 0
	f = 0
	s = []
	n = int(input())
	a = [int(i) for i in input().split()][:n]
	b = [int(i) for i in input().split()][:n]
	for j in range(n):
		d = b[j] - a[j]
		s.insert(j, d)
		if d != 0 and f == 0:
			f = 1
			k = d
			l = j
		if d == 0 and f == 1:
			r = j
			break
		if j == n - 1:
			r = n
	for j in range(l, r, 1):
		a[j] = a[j] + k
	if a == b and k >= 0:
		g.insert(i, 'YES')
	else:
		g.insert(i, 'NO')
print(*g, sep='\n')


def check():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = [b[i] - a[i] for i in range(n)]
	start = 0
	end = n - 1
	while start < n:
		if diff[start] < 0:
			return False
		if diff[start] > 0:
			break
		start += 1
	if start == n:
		return True
	while end > 0:
		if diff[end] < 0:
			return False
		if diff[end] > 0:
			break
		end -= 1
	return diff[start:end + 1] == [diff[start]] * (end - start + 1) and diff[start] > 0
cases = int(input())
for _ in range(cases):
	if check():
		print('YES')
	else:
		print('NO')


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def pred(n, k, pointer):
	return pointer - k >= n

def yes():
	print('YES')

def no():
	print('NO')
Testcase = inin()
for n in range(Testcase):
	n = inin()
	a = inar()
	b = inar()
	d = []
	poss = True
	for i in range(n):
		c = b[i] - a[i]
		positive = 0
		if c < 0:
			poss = False
			break
		else:
			d.append(c)
	if poss:
		d.insert(0, 0)
		d.append(0)
		cnt = 0
		for i in range(0, n + 1):
			if d[i] != d[i + 1]:
				cnt += 1
		if cnt == 0 or cnt == 2:
			yes()
		else:
			no()
	else:
		no()


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = []
	l2 = []
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = [i - j for (i, j) in zip(l1, l2)]
	i = 0
	j = len(l3) - 1
	while i < len(l3) and l3[i] == 0:
		i += 1
	while j >= 0 and l3[j] == 0:
		j -= 1
	if j == -1 or (len(set(l3[i:j + 1])) == 1 and l3[i] < 0):
		print('YES')
	else:
		print('NO')


T = int(input())
s = []
for t in range(T):
	dif = 0
	h = 0
	n = int(input())
	a = [int(k) for k in input().split()]
	b = [int(k) for k in input().split()]
	for i in range(n):
		if a[i] == b[i]:
			continue
		else:
			dif = b[i] - a[i]
			h = i
			break
	if dif < 0:
		a = 0
	else:
		for i in range(h, n):
			if b[i] > a[i]:
				a[i] = a[i] + dif
			elif a[i] < b[i]:
				a = 0
			else:
				break
	if a == b:
		s.append('YES')
	else:
		s.append('NO')
for i in s:
	print(i)


x = eval(input())
for i in range(x):
	y = input()
	y = list(map(int, input().split(' ')))
	z = list(map(int, input().split(' ')))
	for j in range(len(y)):
		y[j] = z[j] - y[j]
	c = 0
	z = 0
	k = True
	m = 3
	for i in range(len(y)):
		if c != y[i] and y[i] != 0:
			c = y[i]
	if y[0] != 0:
		m = 1
	for i in range(1, len(y)):
		if y[i] != y[i - 1]:
			z += 1
	for i in range(len(y)):
		if y[i] != c:
			y[i] += c
		if y[i] != c or y[i] < 0:
			k = False
	if not k or z > 2 or (z > 1 and m == 1):
		print('NO')
	else:
		print('YES')


def p():
	l = []
	for j in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		(o, r, m) = ([], 1, 0)
		for i in range(n):
			if a[i] != b[i]:
				k = a[i] - b[i]
				if k > 0:
					l.append('NO')
					r = 0
					break
				elif not o:
					o.append(k)
					m = i
				elif k != o[0] or m + 1 != i:
					l.append('NO')
					r = 0
					break
				else:
					m = i
		if r:
			l.append('YES')
	print('\n'.join(l))
p()


def findk(a, b):
	(start, k, end) = (-1, -1, -1)
	for i in range(len(a)):
		if a[i] == b[i]:
			if start != -1:
				if k != 0:
					k = 0
		elif start == -1:
			(start, end, k) = (i, i, b[i] - a[i])
			if k < 0:
				return (-1, -1, -1)
		elif k == b[i] - a[i]:
			end += 1
		else:
			return (-1, -1, -1)
	if start == -1:
		k = 0
	return (start, end, k)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(l, r, k) = findk(a, b)
	if k == -1:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [0] * n
	for i in range(n):
		c[i] = b[i] - a[i]
	flg = 0
	ok = 1
	for i in range(n):
		if flg == 1:
			if c[i] != val and c[i] != 0:
				ok = 0
				break
			elif c[i] == 0:
				flg = 2
		elif flg == 0:
			if c[i] != 0:
				flg = 1
				val = c[i]
				if val < 0:
					ok = 0
					break
		elif flg == 2:
			if c[i] != 0:
				ok = 0
				break
	if ok:
		print('YES')
	else:
		print('NO')


def solv():
	n = int(input())
	for _ in range(n):
		bol = False
		l = int(input())
		s1 = input().split()
		s2 = input().split()
		fla = int(s2[0]) - int(s1[0])
		ans = int(s2[0]) - int(s1[0])
		we = int(s2[l - 1]) - int(s1[l - 1])
		up = 0
		down = 0
		if ans < 0:
			bol = True
		for i in range(1, l):
			cc = int(s2[i]) - int(s1[i])
			if cc < 0:
				bol = True
				break
			if cc > ans:
				ans = cc
				up += 1
			if cc < ans:
				ans = cc
				down += 1
		if bol == True:
			print('NO')
		else:
			if down == 1 and up == 1 and (we == 0) and (fla == 0):
				bol = True
			if down == 0 and up == 0:
				bol = True
			if fla == 0 and up == 1 and (down == 0):
				bol = True
			if fla != 0 and up == 0 and (down == 1) and (we == 0):
				bol = True
			if bol:
				print('YES')
			else:
				print('NO')
solv()


tc = int(input())
while tc > 0:
	tc -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	df = 0
	i = 0
	fg = 0
	while i < n:
		while i < n and a[i] == b[i]:
			i += 1
		if i < n:
			cnt += 1
			df = b[i] - a[i]
		else:
			break
		while i < n and a[i] != b[i]:
			if df != b[i] - a[i] or df < 0:
				fg = 1
				break
			i += 1
		if fg == 1:
			break
	if fg == 0 and cnt <= 1:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cur_diff = -1
	try:
		for i in range(n):
			ai = a[i]
			bi = b[i]
			diff = bi - ai
			assert diff >= 0
			if cur_diff == -1:
				if diff > 0:
					cur_diff = diff
			elif cur_diff > 0:
				if diff == 0:
					cur_diff = 0
				assert diff == cur_diff
			elif cur_diff == 0:
				assert diff == cur_diff
		print('YES')
	except AssertionError:
		print('NO')


def solve(a, b):
	c = [b[i] - a[i] for i in range(len(a))]
	(ldif0, rdif0) = (-1, -1)
	for i in range(len(c)):
		if c[i] != 0:
			ldif0 = i
			break
	for i in range(len(c) - 1, -1, -1):
		if c[i] != 0:
			rdif0 = i
			break
	dif = c[ldif0]
	for i in range(ldif0, rdif0 + 1):
		if c[i] != dif or c[i] < 0:
			print('NO')
			return
	print('YES')
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	solve(a, b)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	(x, index, count) = ([], 0, 0)
	x.append(0)
	for j in range(n):
		x.append(b[j] - a[j])
	x.append(0)
	for k in range(0, len(x) - 1):
		if x[k] != x[k + 1]:
			count += 1
	print('YES' if count <= 2 and sorted(x)[0] >= 0 else 'NO')


a = int(input())
for i in range(0, a):
	b = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	crr = []
	for i in range(0, len(arr)):
		crr.append(brr[i] - arr[i])
	trr = []
	left = 0
	right = len(arr) - 1
	li = 0
	pivot = 0
	for i in range(0, len(crr)):
		if not crr[i] == 0:
			pivot = crr[i]
			li = i
			break
	ri = len(arr) - 1
	for j in range(len(crr) - 1, -1, -1):
		if not crr[j] == 0:
			ri = j
			break
	k = 0
	for i in range(0, len(arr)):
		if i >= li and i <= ri:
			if not crr[i] == pivot or crr[i] < 0:
				k = 1
				break
	if k == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for ti in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	c = []
	fg1 = fg2 = 0
	dd = 0
	for i in range(n):
		if fg1 == 2 and a[i] != b[i]:
			fg2 = 1
			print('NO')
			break
		if a[i] != b[i] and fg1 == 0:
			dd = b[i] - a[i]
			if dd < 0:
				fg2 = 1
				print('NO')
				break
			fg1 = 1
		if fg1 == 1:
			if a[i] + dd != b[i]:
				if a[i] != b[i]:
					print('NO')
					fg2 = 1
					break
				else:
					fg1 = 2
	if fg2:
		pass
	else:
		print('YES')


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


n = int(input())
for i in range(n):
	a = int(input())
	list1 = [int(x) for x in input().split(' ')]
	list2 = [int(x) for x in input().split(' ')]
	d = 0
	dd = 0
	c = 0
	for j in range(a):
		if list1[j] > list2[j]:
			print('NO')
			c = 1
			break
		elif list1[j] < list2[j]:
			if d == 1:
				print('NO')
				c = 1
				break
			elif dd == 0:
				dd = list1[j] - list2[j]
			elif dd != list1[j] - list2[j]:
				print('NO')
				c = 1
				break
		elif dd != 0:
			d = 1
			dd = 0
	if c == 0:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [0 for i in range(n)]
	if a == b:
		print('YES')
	else:
		broke = False
		for i in range(n):
			c[i] = b[i] - a[i]
			if c[i] < 0:
				broke = True
				break
		if not broke:
			first_not_0 = c.index(next(filter(lambda ci: ci != 0, c)))
			k = c[first_not_0]
			found_0 = False
			for i in range(first_not_0, n):
				if c[i] == 0:
					found_0 = True
				if c[i] != 0 and (c[i] != k or found_0):
					broke = True
					break
		if broke:
			print('NO')
		else:
			print('YES')


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


t = int(input())
while t != 0:
	t -= 1
	a = []
	b = []
	nx = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = []
	d = ' '
	d = ''
	flag = 0
	for i in range(0, len(a)):
		c.append(b[i] - a[i])
		if b[i] - a[i] < 0:
			flag = 1
	if flag == 0:
		x = set(c)
		(count1, count2) = (0, len(c))
		if len(x) > 2:
			print('NO')
		elif 0 not in x and len(x) >= 2:
			print('NO')
		elif len(a) == 1 and a[0] <= b[0]:
			print('YES')
		else:
			for i in c:
				if i == 0:
					count1 += 1
				else:
					break
			for i in c[::-1]:
				if i == 0:
					count2 -= 1
				else:
					break
			if 0 in c[count1:count2]:
				print('NO')
			else:
				print('YES')
	else:
		print('NO')


import os
import sys

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		A = read_ints()
		B = read_ints()
		print('YES' if solve(N, A, B) else 'NO')

def solve(N, A, B):
	D = [B[i] - A[i] for i in range(N)]
	C = []
	i = 0
	while i < N:
		j = i + 1
		while j < N and D[i] == D[j]:
			j += 1
		C.append(D[i])
		i = j
	dprint(D)
	dprint(C)
	if len(C) == 1 and C[0] >= 0:
		return True
	if len(C) == 2 and 0 in C and (C[0] >= 0) and (C[1] >= 0):
		return True
	if len(C) == 3 and C[0] == 0 and (C[2] == 0) and (C[1] > 0):
		return True
	return False
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	nval = 0
	f = 0
	g = 0
	for i in range(0, n):
		val = m[i] - l[i]
		if nval == 0:
			nval = val
		if val < 0:
			print('NO')
			g = 1
			break
		if nval != val and val > 0:
			print('NO')
			g = 1
			break
		if nval != 0 and val == 0:
			f = 1
			continue
		if val == nval and f == 1:
			print('NO')
			g = 1
			break
		nval = val
	if g == 0:
		print('YES')


for _ in range(int(input())):
	am = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	for i in range(am):
		arr2[i] -= arr1[i]
	s = set(arr2)
	if len(s) == 1 and list(s)[0] >= 0:
		print('YES')
	elif len(s) == 2 and 0 in s:
		l = sorted(list(s))
		if l[0] < 0:
			print('NO')
		else:
			t = l[1]
			fl1 = False
			fl2 = False
			for i in range(len(arr2)):
				if arr2[i] == t:
					if not fl1:
						fl1 = True
					elif fl2:
						print('NO')
						break
				elif fl1:
					fl2 = True
			else:
				print('YES')
	else:
		print('NO')


t = int(input())
res = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = False
	for j in range(n):
		if a[j] != b[j] and f is False:
			l = j
			f = True
			k = b[j] - a[j]
			if k < 0:
				break
		if a[j] == b[j] and f is True:
			r = j - 1
			break
		if f is True and a[j] != b[j]:
			a[j] += k
	yes = True
	for j in range(n):
		if a[j] != b[j]:
			yes = False
			break
	if yes == True:
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	p = []
	for i in range(n):
		if a[i] != b[i]:
			l.append(b[i] - a[i])
			p.append(i)
	f = 1
	for i in range(len(p) - 1):
		if p[i + 1] - p[i] != 1:
			f = 0
	for i in range(len(l)):
		if l[i] < 0:
			f = 0
	if len(set(l)) == 1 and f == 1 or len(l) == 0:
		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 == b:
		print('YES')
		continue
	diffs = []
	flag = False
	for i in range(n):
		if a[i] < b[i]:
			diffs.append((i, b[i] - a[i]))
		elif a[i] > b[i]:
			print('NO')
			flag = True
			break
	if flag:
		continue
	for i in range(1, len(diffs)):
		(pre_idx, pre_diff) = diffs[i - 1]
		(idx, diff) = diffs[i]
		if pre_idx + 1 != idx or pre_diff != diff:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = [0] * n
	fl = False
	for i in range(n):
		diff[i] = b[i] - a[i]
		if diff[i] < 0:
			fl = True
	if fl:
		print('NO')
		continue
	diffL = 0
	idL = 0
	for i in range(n):
		if diff[i] != 0:
			diffL = diff[i]
			idL = i
			break
	diffR = 0
	idR = 0
	for i in range(n - 1, -1, -1):
		if diff[i] != 0:
			diffR = diff[i]
			idR = i
			break
	if diffL != diffR:
		print('NO')
	else:
		ans = 'YES'
		for i in range(idL, idR + 1):
			if diff[i] != diffL:
				ans = 'NO'
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	i = 0
	k = []
	flag = 1
	flag1 = 1
	while i < n:
		if a[i] > b[i]:
			flag = 0
			break
		elif a[i] == b[i]:
			i = i + 1
		else:
			k.append(i)
			i = i + 1
	if flag == 0:
		print('NO')
	else:
		for i in range(len(k)):
			if i == 0:
				con = b[k[i]] - a[k[i]]
			elif k[i] != k[i - 1] + 1 or b[k[i]] - a[k[i]] != con:
				print('NO')
				flag1 = 0
				break
		if flag1 != 0:
			print('YES')


t = int(input())
for _ in range(t):
	index = []
	diff = []
	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]:
			index.append(i)
			diff.append(b[i] - a[i])
	x = len(index)
	flag = 1
	if x == 1:
		if diff[0] < 0:
			print('NO')
			continue
		else:
			print('YES')
			continue
	for i in range(x - 1):
		if index[i + 1] - index[i] != 1 or diff[i] < 0 or diff[i] != diff[i + 1]:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	c = []
	d = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('YES')
	elif a > b:
		print('NO')
	else:
		for j in range(n):
			if b[j] - a[j] != 0:
				c.append(b[j] - a[j])
				d.append(j)
		for k in range(len(d) - 1):
			d[k] = d[k + 1] - d[k]
		d[len(d) - 1] -= (d[len(d) - 1] - 1) * d[len(d) - 2]
		if len(set(c)) == 1 and len(set(d)) == 1:
			print('YES')
		else:
			print('NO')


def do():
	N = int(input())
	for _ in range(N):
		K = int(input())
		ch1 = input()
		ch1 = [int(i) for i in ch1.split()]
		ch2 = input()
		ch2 = [int(i) for i in ch2.split()]
		if ch1 == ch2:
			print('YES')
			continue
		verif = 1
		for i in range(len(ch1)):
			if ch2[i] < ch1[i]:
				print('NO')
				verif = 0
				break
		if verif == 0:
			continue
		test1 = 0
		ch3 = []
		for i in range(len(ch1)):
			ch3.append(ch2[i] - ch1[i])
		v = 1
		ch4 = []
		for i in range(len(ch3)):
			if ch3[i] != 0 or v == 0:
				ch4.append(ch3[i])
				v = 0
		ch4.reverse()
		v = 1
		ch5 = []
		for i in range(len(ch4)):
			if ch4[i] != 0 or v == 0:
				ch5.append(ch4[i])
				v = 0
		if len(set(ch5)) == 1:
			print('YES')
			continue
		print('NO')
do()


def solve(arr1, arr2, n):
	index = -1
	for i in range(n):
		if arr1[i] != arr2[i]:
			index = i
			diff = arr2[i] - arr1[i]
			break
	if index == -1:
		print('YES')
		return
	if diff < 0:
		print('NO')
		return
	for i in range(index, n):
		if arr1[i] == arr2[i]:
			break
		curr = arr2[i] - arr1[i]
		if curr != diff:
			print('NO')
			return
		arr2[i] = arr1[i]
	for i in range(n):
		if arr1[i] != arr2[i]:
			print('NO')
			return
	print('YES')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr1 = list(map(int, input().split()))
		arr2 = list(map(int, input().split()))
		solve(arr1, arr2, n)
main()


def f():
	t = int(input())
	for _ in range(t):
		_ = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		s = 0
		r = True
		for (x, y) in zip(a, b):
			if r:
				if x == y:
					if s != 0:
						s = -2
				elif x < y:
					if s == 0:
						s = y - x
					if y - x != s:
						r = False
				else:
					r = False
		print('YES') if r else print('NO')
f()


def function(a, b, n):
	pointer = 0
	difference = 0
	count = 0
	while pointer < n:
		if b[pointer] - a[pointer] == difference:
			pointer += 1
		elif a[pointer] > b[pointer]:
			return 'NO'
		elif count == 0:
			difference = b[pointer] - a[pointer]
			count += 1
			pointer += 1
		elif b[pointer] == a[pointer]:
			difference = 0
			pointer += 1
		else:
			return 'NO'
	return 'YES'
m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	print(function(a, b, n))


def A(inp):
	lines = inp.split('\n')
	t = int(lines[0])
	for i in range(t):
		n = int(lines[1 + i * 3])
		a = map(int, lines[2 + i * 3].split())
		b = map(int, lines[3 + i * 3].split())
		v = None
		ans = 'YES'
		for (ai, bi) in zip(a, b):
			if bi - ai != 0:
				if v and bi - ai != v or bi - ai < 0:
					ans = 'NO'
					break
				else:
					v = bi - ai
			elif v and bi - ai == 0:
				v = -1
		print(ans)

def stinp():
	r = input()
	for k in range(3 * int(r)):
		r += '\n' + input()
	return r
A(stinp())


def f(A, B):
	n = len(A)
	i = 0
	while i < n and A[i] == B[i]:
		i += 1
	if i == n:
		return 'YES'
	k = B[i] - A[i]
	s = i
	while s < n and A[s] != B[s]:
		s += 1
	if k >= 0:
		for j in range(i, n):
			if j < s:
				if B[j] - A[j] != k:
					return 'NO'
			elif B[j] - A[j] != 0:
				return 'NO'
		return 'YES'
	else:
		return 'NO'
t = int(input())
while t > 0:
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(f(A, B))
	t -= 1


q = int(input())
for rwerwe in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [b[i] - a[i] for i in range(n)]
	dupa = {}
	for i in range(n):
		if c[i] != 0:
			dupa[c[i]] = 0
	if len(dupa) > 1:
		print('NO')
	if len(dupa) == 0:
		print('YES')
	if len(dupa) == 1:
		if sum(c) < 0:
			print('NO')
		else:
			for i in range(n):
				if c[i] != 0:
					start = i
					break
			for j in range(n):
				i = n - 1 - i
				if c[j] != 0:
					end = j
			if (end - start + 1) * c[start] == sum(c):
				print('YES')
			else:
				print('NO')


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(sys.stdin.readline())

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

def inpl_str():
	return list(sys.stdin.readline().split())
t = inp()
for _ in range(t):
	N = inp()
	aa = inpl()
	bb = inpl()
	l = N - 1
	r = 0
	for i in range(N):
		a = aa[i]
		b = bb[i]
		if a != b:
			l = min(l, i)
			r = max(r, i)
	s = bb[l] - aa[l]
	if s < 0:
		print('NO')
		continue
	for i in range(l, r + 1):
		aa[i] += s
	for i in range(N):
		if aa[i] != bb[i]:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for zxc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list()
	flag = True
	for i in range(n):
		c.append(a[i] - b[i])
	zero = list()
	for i in range(n):
		if c[i] != 0:
			zero.append(i)
			if c[i] > 0:
				flag = False
	delt = 0
	for i in range(len(zero) - 1):
		if c[zero[i]] != c[zero[i + 1]]:
			flag = False
		if zero[i + 1] - zero[i] != 1:
			delt += 1
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(lambda x: int(x), input().split()))
	b = list(map(lambda x: int(x), input().split()))
	c = [b[i] - a[i] for i in range(n)]
	s = -1
	e = -1
	flag = True
	for i in range(n):
		if c[i] < 0:
			flag = False
	for i in range(n):
		if c[i] > 0:
			s = i
			break
	for i in range(n)[::-1]:
		if c[i] > 0:
			e = i
			break
	if not flag:
		print('NO')
	elif s == -1:
		print('YES')
	elif all((x == c[s] for x in c[s:e + 1])):
		print('YES')
	else:
		print('NO')


m = int(input())
liste2 = []
for i in range(m):
	l = k = w = 0
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	w = n
	for j in range(n):
		if a[j] != b[j]:
			l = j
			break
	for j in range(n):
		if a[w - 1] == b[w - 1]:
			w -= 1
		else:
			break
	liste = []
	if l == w:
		liste2.append('YES')
	else:
		for j in range(l, w):
			liste.append(b[j] - a[j])
		liste = list(dict.fromkeys(liste))
		if len(liste) == 1 and liste[0] >= 0:
			liste2.append('YES')
		else:
			liste2.append('NO')
for i in liste2:
	print(i)


t = int(input())
res = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	k = -1
	needToCont = True
	i = 0
	stoped = False
	while needToCont and i < n:
		if a[i] < b[i]:
			if k == -1:
				k = b[i] - a[i]
				i += 1
			elif k != -1 and b[i] - a[i] != k:
				needToCont = False
			elif k != -1 and b[i] - a[i] == k and stoped:
				needToCont = False
			else:
				i += 1
		elif a[i] == b[i]:
			if k != -1:
				stoped = True
			i += 1
		else:
			needToCont = False
	res.append(needToCont)
for i in res:
	print('YES' if i else 'NO')


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


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	i = 0
	x = []
	c = 0
	k = li()
	while i < n:
		if l[i] > k[i]:
			print('NO')
			return
		if l[i] == k[i]:
			i += 1
			continue
		else:
			x.append(i)
			j = i + 1
			p = k[i] - l[i]
			while j < n and k[j] > l[j]:
				if k[j] - l[j] != p:
					c = 1
					break
				j += 1
			i = j
		if c:
			print('NO')
			return
	if len(x) <= 1 and c == 0:
		print('YES')
	else:
		print('NO')
for _ in range(inp()):
	solve()


r = int(input())
for i in range(r):
	h = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	result = 'YES'
	first = True
	firstindice = 0
	lastindice = -1
	for f in range(h):
		if a[f] != b[f]:
			if first:
				first = False
				firstindice = f
				pushval = abs(b[f] - a[f])
				lastindice = f
			else:
				lastindice = f
	for f in range(firstindice, lastindice + 1):
		a[f] += pushval
	if a != b:
		result = 'NO'
	print(result)


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()]
	mode = 0
	mid_delta = 0
	for j in range(n):
		flag = False
		delta = b[j] - a[j]
		if delta < 0:
			print('NO')
			flag = True
			break
		if mode == 0:
			if delta == 0:
				continue
			else:
				mode = 1
				mid_delta = delta
				continue
		if mode == 1:
			if delta == mid_delta:
				continue
			elif delta == 0:
				mode = 2
				continue
			else:
				print('NO')
				flag = True
				break
		if mode == 2:
			if delta == 0:
				continue
			else:
				print('NO')
				flag = True
				break
	if not flag:
		print('YES')


t = int(input())
for f in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		l.append(a[i] - b[i])
	q = w = None
	true = 0
	for i in range(n):
		if l[i] != 0:
			if q != None and w != None:
				true = 1
				break
			elif q == None:
				if l[i] > 0:
					true = 1
					break
				q = i
			elif l[i] != l[i - 1]:
				true = 1
				break
		elif q != None and w == None:
			w = i
	if true:
		print('NO')
	else:
		print('YES')


def main(a, b):
	index = 0
	map1 = {}
	while index < len(a):
		if a[index] != b[index]:
			if a[index] < b[index]:
				map1[index] = b[index] - a[index]
		if a[index] > b[index]:
			return 'NO'
		index = index + 1
	c = list(map1)
	d = find(c)
	if d:
		return 'NO'
	e = []
	index = 0
	while index < len(c):
		e.append(map1[c[index]])
		index = index + 1
	if len(list(set(e))) > 1:
		return 'NO'
	return 'YES'

def find(arr):
	index = 1
	while index < len(arr):
		if abs(arr[index] - arr[index - 1]) > 1:
			return True
		index = index + 1
t = int(input())
for t_itr in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	res = main(a, b)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [0] * n
	l = -1
	r = 97531
	now = 0
	flag = 0
	for x in range(n):
		c[x] = b[x] - a[x]
	for x in range(n):
		if c[x] != 0:
			l = x
			break
	for x in range(n - 1, -1, -1):
		if c[x] != 0:
			r = x
			break
	if l == -1 and r == 97531:
		print('YES')
	else:
		now = c[l]
		if now < 0:
			print('NO')
		else:
			for x in range(l, r + 1):
				if c[x] != now:
					flag = 1
					break
			if flag == 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()))
	ans = []
	for i in range(n):
		ans.append(b[i] - a[i])
	ans = [0] + ans + [0]
	t = 0
	for i in range(n + 1):
		if ans[i] < 0:
			t = 10
			break
		if ans[i] != ans[i + 1]:
			t += 1
	if t > 2:
		print('NO')
	else:
		print('YES')


I = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	A = [b - a for (a, b) in zip(I(), I())]
	i = 0
	while i < n and A[i] == 0:
		i += 1
	if i == n:
		print('YES')
	else:
		j = n - 1
		while A[j] == 0:
			j -= 1
		if A[i] >= 0 and all((A[k] == A[k + 1] for k in range(i, j))):
			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()))
	l = []
	co = 0
	for i in range(n):
		if a[i] < b[i]:
			k = b[i] - a[i]
			for j in range(i, n):
				if a[j] < b[j]:
					a[j] += k
				else:
					break
			break
	if a == b:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	m = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = 0
	c = []
	ii = []
	for i in range(0, m):
		if a[i] == b[i]:
			pass
		elif a[i] < b[i]:
			c.append(b[i] - a[i])
			if len(ii) == 0:
				ii.append(i)
			elif ii[-1] + 1 == i:
				ii.append(i)
				pass
			else:
				p = 1
				break
		else:
			p = 1
			break
	if p == 1:
		print('NO')
	elif len(set(c)) == 1 or len(set(c)) == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	res = 'YES'
	diff = -1
	end_diff = False
	for i in range(n):
		if a[i] > b[i]:
			res = 'NO'
			break
		if b[i] > a[i]:
			if diff == -1:
				diff = b[i] - a[i]
			elif end_diff or b[i] - a[i] != diff:
				res = 'NO'
				break
		if diff > 0 and b[i] == a[i]:
			end_diff = True
	print(res)


raz = int(input())
L = -1
R = -1
fl = True
for i in range(raz):
	leni = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for j in range(leni):
		if A[j] != B[j]:
			if L == -1:
				L = j
			else:
				R = j
		elif L != -1 and A[j] == B[j]:
			break
	K = B[L] - A[L]
	if L != -1 and K > 0:
		if R == -1:
			R = L
		for g in range(R - L + 1):
			A[L + g] += K
	for k in range(leni):
		if A[k] != B[k]:
			print('NO')
			fl = False
			break
	if fl == True:
		print('YES')
	fl = True
	L = -1
	R = -1


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	a = list((int(p) for p in a))
	b = input().split()
	b = list((int(p) for p in b))
	c = []
	d = []
	flag = 0
	if len(a) == 1 and a[0] <= b[0]:
		print('YES')
	elif len(a) == 1 and a[0] > b[0]:
		print('NO')
	else:
		for i in range(len(b)):
			if b[i] - a[i] != 0:
				d.append(b[i] - a[i])
				c.append(i)
		if len(d) == 0 or (len(d) == 1 and d[0] > 0):
			print('YES')
		elif len(d) == 1 and d[0] < 0:
			print('NO')
		else:
			for i in range(len(d) - 1):
				if d[i] != d[i + 1] or c[i + 1] - c[i] != 1 or d[i] < 0 or (d[i + 1] < 0):
					print('NO')
					flag = 1
					break
			if flag == 0:
				print('YES')


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


t = input('')
t = int(t)
outs = []
if 1 <= t <= 20:
	for i in range(t):
		can = True
		out = []
		n = input('')
		in1 = input('')
		in2 = input('')
		n = int(n)
		a = in1.split()
		b = in2.split()
		l = 0
		k = 1
		r = n
		for j in range(n):
			out.append(int(b[j]) - int(a[j]))
		for j in range(n):
			if out[j] != 0:
				l = j
				k = out[j]
				break
		if k < 0:
			can = False
		if n > 1:
			for j in range(l, n):
				if out[j] == 0:
					r = j
					break
				if int(a[j]) + k != int(b[j]):
					can = False
					break
			while r < n:
				if out[r] != 0:
					can = False
					break
				r += 1
		elif n == 1 and k < 0:
			can = False
		if can:
			outs.append('YES')
		else:
			outs.append('NO')
for i in range(len(outs)):
	print(outs[i])


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


t = int(input())
answer = []
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	flag = True
	count = 0
	for i in range(n):
		if a[i] == b[i] and count > 0:
			count = -1
		elif a[i] != b[i]:
			if count == 0:
				count = b[i] - a[i]
				if b[i] - a[i] < 0:
					flag = False
			elif count == -1:
				flag = False
			elif b[i] - a[i] != count:
				flag = False
		if not flag:
			break
	if flag:
		answer.append('YES')
	else:
		answer.append('NO')
for i in answer:
	print(i)


for i in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	c = []
	for j in range(n):
		k = b[j] - a[j]
		if k < 0:
			print('NO')
			break
		c.append(k)
	if len(c) < n:
		continue
	(l, r) = (-1, -2)
	for j in range(n):
		if c[j] > 0:
			if l < 0:
				l = j
			r = j
	if l <= r:
		for j in range(l + 1, r + 1):
			if c[l] != c[j]:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('YES')


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff = 0
	j = 0
	ok = True
	no_more = False
	while j < n:
		if a[j] > b[j]:
			ok = False
			break
		if a[j] != b[j]:
			if no_more:
				ok = False
				break
			if diff == 0:
				diff = b[j] - a[j]
			elif diff != b[j] - a[j]:
				ok = False
				break
		elif diff != 0:
			no_more = True
		j += 1
	if ok:
		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()))
	i = 0
	c = 0
	z = 0
	while i < n:
		if a[i] != b[i]:
			c = b[i] - a[i]
			if c < 0:
				print('NO')
				z = 1
				break
			i += 1
			while i < n and a[i] != b[i]:
				if b[i] - a[i] != c:
					break
				i += 1
			break
		i += 1
	while i < n and a[i] == b[i]:
		i += 1
	if z == 0:
		if i == n:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	brr = [int(i) for i in input().split()]
	num = 0
	for i in range(n):
		temp = brr[i] - arr[i]
		if temp < 0:
			break
		if temp != 0:
			if num == 0:
				num = temp
			elif temp != num:
				break
			arr[i] += num
		elif num != 0:
			break
	if arr == brr:
		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()))
	c = -1
	kq = 1
	for j in range(n):
		if a[j] > b[j]:
			kq = 0
			break
		elif a[j] < b[j]:
			c = j
			break
	if kq == 0:
		print('NO')
	elif c == -1:
		print('YES')
	else:
		d = n
		for j in range(c + 1, n):
			if b[c] - a[c] != b[j] - a[j]:
				d = j
				break
		for j in range(d, n):
			if b[j] != a[j]:
				kq = 0
				break
			else:
				kq = 1
		if kq == 0:
			print('NO')
		else:
			print('YES')


t = int(input())
i = 0
while i < t:
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	diff = []
	if n == 1:
		d = arr2[n - 1] - arr1[n - 1]
		if d < 0:
			print('NO')
		else:
			print('YES')
	else:
		for x in range(n):
			a = arr2[x] - arr1[x]
			diff.append(a)
		count = 0
		diff.insert(0, 0)
		diff.append(0)
		neg = True
		for x in range(1, n + 2):
			if diff[x] < 0:
				neg = False
			if diff[x] == diff[x - 1]:
				pass
			else:
				count = count + 1
		if neg == False:
			print('NO')
		elif count > 2:
			print('NO')
		elif count <= 2:
			print('YES')
	i = i + 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = []
	for i in range(n):
		res.append(b[i] - a[i])
	l = 0
	l_u = True
	r = n - 1
	r_d = True
	while l_u or r_d:
		if res[l] == 0 and l < n - 1:
			l += 1
		else:
			l_u = False
		if res[r] == 0 and r > 0:
			r -= 1
		else:
			r_d = False
	isneg = 0
	diff = res[l]
	isdiff = 1
	for i in range(l, r + 1):
		if res[i] < 0:
			isneg = 1
		if res[i] != diff:
			isdiff = 0
	if isneg == 0 and isdiff == 1 or (len(set(res)) == 0 and isneg == 0):
		print('YES')
	else:
		print('NO')


z = int(input())
for i in range(z):
	answer = 'YES'
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = [0] * n
	for i in range(n):
		k[i] = b[i] - a[i]
		if k[i] < 0:
			answer = 'NO'
	r = 0
	for i in range(1, n):
		if k[i] != k[i - 1]:
			r += 1
	if k[0] == 0:
		r -= 1
	if k[-1] == 0:
		r -= 1
	if r > 0:
		answer = 'NO'
	print(answer)


t = int(input(''))
aa = []
bb = []
for i in range(t):
	input('')
	aa.append(list(map(int, input().split())))
	bb.append(list(map(int, input().split())))
for i in range(t):
	a = aa[i]
	b = bb[i]
	n = len(a)
	t = []
	for j in range(n):
		if a[j] != b[j]:
			t.append(j)
	flag = 0
	if len(t) == 0:
		print('YES')
		continue
	if len(t) == 1:
		if a[t[0]] - b[t[0]] > 0:
			print('NO')
		else:
			print('YES')
		continue
	for j in range(len(t) - 1):
		if t[j + 1] - t[j] > 1:
			flag = 1
			break
	if flag:
		print('NO')
		continue
	diff = a[t[0]] - b[t[0]]
	if diff > 0:
		print('NO')
		continue
	sign = 0
	for k in t:
		if a[k] - b[k] != diff:
			sign = 1
			break
	if sign:
		print('NO')
	else:
		print('YES')


import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	b = [int(item) for item in input().split()]
	c = []
	for (aa, bb) in zip(a, b):
		c.append(bb - aa)
	status = 0
	num = None
	for item in c:
		if item < 0:
			status = 3
		if status == 0 and item != 0:
			num = item
			status = 1
		elif status == 1:
			if item == 0:
				status = 2
			elif item != num:
				status = 3
		elif status == 2 and item != 0:
			status = 3
	if status == 3:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = [*map(int, input().split())]
	m = [*map(int, input().split())]
	flag = False
	k = 0
	s = set()
	i = 0
	flag1 = True
	arr = []
	s = set()
	while i < n:
		s.add(l[i] - m[i])
		if l[i] != m[i] and k == 0:
			k = l[i] - m[i]
			if k > 0:
				flag1 = False
				break
			arr.append(i)
			i += 1
			continue
			flag = True
		if flag1 and l[i] != m[i] and (l[i] - m[i] != k):
			flag1 = False
			break
		if flag1 and l[i] != m[i] and (l[i] - m[i] == k):
			arr.append(i)
			if arr[-1] - arr[-2] != 1:
				flag1 = False
				break
		i += 1
	if flag1 and len(s) <= 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) - a[i] for (i, x) in enumerate(input().split())]
	for (i, x) in enumerate(b):
		if x != 0:
			break
	for j in range(n - 1, i - 1, -1):
		if b[j] != 0:
			break
	s = set(b[i:j + 1])
	if len(s) == 0 or (len(s) == 1 and s.pop() >= 0):
		print('YES')
	else:
		print('NO')


t = input()
isOkLi = []
for i in range(int(t)):
	n = input()
	a = input()
	b = input()
	al = a.split(' ')
	bl = b.split(' ')
	ldif = -1
	isOk = True
	for ii in range(int(n)):
		dif = int(bl[ii]) - int(al[ii])
		if dif < 0:
			isOk = False
			break
		if dif > 0:
			if ldif == 0:
				isOk = False
				break
			if ldif > 0:
				if ldif != dif:
					isOk = False
					break
			ldif = dif
		elif ldif > 0:
			ldif = 0
	isOkLi.append(isOk)
for l in isOkLi:
	if l:
		print('YES')
	else:
		print('NO')


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	(l, r, k, d, f) = (-1, -1, 0, 0, 'YES')
	for i in range(n):
		if a[i] != b[i]:
			if l == -1:
				l = i
			elif r != -1:
				f = 'NO'
			if d == 0 and b[i] - a[i] > 0:
				d = b[i] - a[i]
			elif d != b[i] - a[i] or b[i] - a[i] < 0:
				f = 'NO'
		elif l != -1 and r == -1:
			r = i
	print(f)


import sys
input = sys.stdin.readline
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	c = [y - x for (x, y) in zip(a, b)]
	d = 0
	e = 0
	ans = 'YES'
	if len(set(c)) > 2 or (len(set(c)) == 2 and 0 not in set(c)):
		ans = 'NO'
	for x in c:
		if x < 0:
			ans = 'NO'
			break
		if x != d:
			d = x
			e += 1
		if e > 2:
			ans = 'NO'
			break
	print(ans)


t = int(input())

def sp(n, a, b):
	(startc, diffc) = (0, 0)
	diff = 0
	if a[0] != b[0]:
		diff = b[0] - a[0]
		if diff < 0:
			return 'NO'
		diffc += 1
		startc += 1
	for j in range(1, n):
		if a[j] != b[j]:
			temp = b[j] - a[j]
			if temp < 0:
				return 'NO'
			if temp != diff:
				diff = temp
				diffc += 1
				if diffc > 1:
					return 'NO'
			if a[j - 1] == b[j - 1]:
				startc += 1
				if startc > 1:
					return 'NO'
	return 'YES'
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(sp(n, a, b))


n = int(input())
for i in range(0, n):
	o = int(input())
	T = 0
	M = 0
	G = 0
	M2 = 0
	p = input().rstrip().split(' ')
	q = input().rstrip().split(' ')
	if p == q:
		print('YES')
	else:
		for i in range(0, len(p)):
			if p[i] == q[i]:
				continue
			elif int(p[i]) > int(q[i]):
				G = 1
				break
			else:
				M = abs(int(p[i]) - int(q[i]))
				A = i
				break
		if G == 1:
			print('NO')
		else:
			for i in range(len(p) - 1, -1, -1):
				if p[i] != q[i]:
					if int(p[i]) > int(q[i]):
						G = 1
						break
					else:
						M2 = abs(int(p[i]) - int(q[i]))
						B = i
						break
			if G == 1 or M != M2:
				print('NO')
			else:
				for i in range(0, len(p)):
					if i >= A and i <= B:
						p[i] = str(int(p[i]) + M)
				if p == q:
					print('YES')
				else:
					print('NO')


import sys
queries = int(sys.stdin.readline())

def doQueries(queries):
	for query in range(queries):
		length = int(sys.stdin.readline())
		arr1 = sys.stdin.readline().strip().split()
		arr2 = sys.stdin.readline().strip().split()
		pos = 0
		differences = 0
		changed = False
		while pos < length:
			if arr1[pos] != arr2[pos]:
				if changed == False:
					lastK = int(arr2[pos]) - int(arr1[pos])
					differences += 1
					changed = True
					if differences > 1:
						break
				if int(arr1[pos]) > int(arr2[pos]):
					differences = 2
					break
				if lastK != int(arr2[pos]) - int(arr1[pos]):
					differences = 2
					break
			else:
				changed = False
			pos += 1
		if differences > 1:
			print('NO')
		else:
			print('YES')
doQueries(queries)


for _ in range(int(input())):
	n = int(input())
	v = []
	d = 0
	di = []
	q = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for (i, j) in zip(a, b):
		if i != j:
			d = j - i
			di.append(d)
			v.append(d)
		elif i == j:
			g = j - i
			v.append(g)
	if len(set(di)) == 0:
		print('YES')
	elif len(set(di)) == 1 and di[0] > 0:
		ans = 'YES'
		flag = 0
		index_ = v.index(di[0])
		for i in range(index_, len(v)):
			if v[i] == di[0]:
				if flag == 1:
					ans = 'NO'
					break
			else:
				flag = 1
		print(ans)
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	set_diff = list(set((b[i] - a[i] for i in range(n))))
	if len(set_diff) > 2:
		print('NO')
	elif len(set_diff) == 2:
		if set_diff[0] < 0 or set_diff[1] < 0:
			print('NO')
		elif set_diff[0] > 0 and set_diff[1] > 0:
			print('NO')
		else:
			d = c = 0
			for i in range(n):
				diff = b[i] - a[i]
				if d == 0 and diff != 0:
					c += 1
					d = diff
				if diff == d:
					continue
				elif diff == 0:
					d = 0
			if c == 1:
				print('YES')
			else:
				print('NO')
	elif set_diff[0] >= 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	mass1 = list(map(int, input().split()))
	mass2 = list(map(int, input().split()))
	l = -1
	r = -1
	k = 0
	fl = 'YES'
	for i in range(n):
		if mass2[i] - mass1[i] != 0:
			if r != -1:
				fl = 'NO'
				break
			if l == -1:
				l = i
				k = mass2[i] - mass1[i]
				if k < 0:
					fl = 'NO'
					break
			elif mass2[i] - mass1[i] != k:
				fl = 'NO'
				break
		elif l != -1:
			r = i - 1
		else:
			continue
	print(fl)


cases = int(input())
for cas in range(cases):
	n = int(input())
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	sol = []
	for x in range(n):
		sol.append(arr2[x] - arr1[x])
	comp = 0
	item = 0
	status = False
	for x in range(n):
		if sol[x] > 0 and (not status):
			status = True
			item = sol[x]
			comp += 1
		if sol[x] > 0 and status:
			if item != sol[x]:
				comp = 10000000000
				break
			continue
		if sol[x] == 0:
			status = False
		if sol[x] < 0:
			comp = 10000000000
			break
	if comp > 1:
		print('NO')
	else:
		print('YES')