During cleaning the coast, Alice found $n$ piles of stones. The $i$-th pile has $a_i$ stones.

Piles $i$ and $i + 1$ are neighbouring for all $1 \leq i \leq n - 1$. If pile $i$ becomes empty, piles $i - 1$ and $i + 1$ doesn't become neighbouring.

Alice is too lazy to remove these stones, so she asked you to take this duty. She allowed you to do only the following operation:

Select two neighboring piles and, if both of them are not empty, remove one stone from each of them.

Alice understands that sometimes it's impossible to remove all stones with the given operation, so she allowed you to use the following superability:

Before the start of cleaning, you can select two neighboring piles and swap them.

Determine, if it is possible to remove all stones using the superability not more than once.


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

The first line of each test case contains the single integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the number of piles.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) — the number of stones in each pile.

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


-----Output-----

For each test case, print YES or NO — is it possible to remove all stones using the superability not more than once or not.


-----Examples-----

Input
5
3
1 2 1
3
1 1 2
5
2 2 2 1 3
5
2100 1900 1600 3000 1600
2
2443 2445
Output
YES
YES
YES
YES
NO


-----Note-----

In the first test case, you can remove all stones without using a superability: $[1, 2, 1] \rightarrow [1, 1, 0] \rightarrow [0, 0, 0]$.

In the second test case, you can apply superability to the second and the third piles and then act like in the first testcase.

In the third test case, you can apply superability to the fourth and the fifth piles, thus getting $a = [2, 2, 2, 3, 1]$.

In the fourth test case, you can apply superability to the first and the second piles, thus getting $a = [1900, 2100, 1600, 3000, 1600]$.

Difficulty: HARD
Tags: Dynamic programming

Data structures

Mathematics

Greedy algorithms
Skill types: Dynamic programming

Data structures

Greedy algorithms

Starter code:

Solutions:
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')
for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [-1] * (n + 1)
	l1[n - 1] = l[-1]
	l1[-1] = 0
	c = 0
	for i in range(n - 2, -1, -1):
		l1[i] = l[i] - l1[i + 1]
		if l1[i] < 0:
			l1[i] = -1
			break
	ans = 'NO'
	for i in range(n - 1):
		if l[i + 1] - c == l[i] - l1[i + 2] and l[i + 1] - c >= 0 and (l1[i + 2] != -1):
			ans = 'YES'
			break
		c = l[i] - c
		if c < 0:
			break
	for i in range(1, n):
		l[i] -= l[i - 1]
		if l[i] < 0:
			break
		if i == n - 1 and l[i] == 0:
			ans = 'YES'
	print(ans)


def solve2(X):
	return X[0] == X[1]

def s3h(a, b, c):
	return solveN_nosuper([a, b, c])

def solve3(X):
	(a, b, c) = X
	return s3h(a, b, c) or s3h(b, a, c) or s3h(a, c, b)

def s4h(a, b, c, d):
	if min(a, b, c, d) < 0:
		return False
	return solveN_nosuper([a, b, c, d])

def solve4(X):
	(a, b, c, d) = X
	return s4h(a, b, c, d) or s4h(b, a, c, d) or s4h(a, c, b, d) or s4h(a, b, d, c)

def solveN_nosuper(X):
	X = X.copy()
	for i in range(len(X) - 1):
		if X[i] > X[i + 1]:
			return False
		X[i + 1] -= X[i]
		X[i] = 0
	return X[-1] == 0

def fix(X):
	X = X.copy()
	ret = [X[0]]
	for i in range(1, len(X)):
		if ret[i - 1] == -1 or X[i - 1] > X[i]:
			ret.append(-1)
		else:
			X[i] -= X[i - 1]
			X[i - 1] = 0
			ret.append(X[i])
	return ret

def solveN(X):
	if solveN_nosuper(X):
		return True
	L = [0] + fix(X) + [0]
	R = [0] + fix(X[::-1])[::-1] + [0]
	X = [0] + X + [0]
	for i in range(1, len(X) - 2):
		if s4h(L[i - 1], X[i + 1], X[i], R[i + 2]):
			return True
	return False
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	if N == 2:
		ans = solve2(A)
	elif N == 3:
		ans = solve3(A)
	elif N == 4:
		ans = solve4(A)
	else:
		ans = solveN(A)
	print('YES' if ans else 'NO')


import sys, io, os
if os.environ['USERNAME'] == 'kissz':
	inp = open('in4.txt', 'r').readline

	def debug(*args):
		print(*args, file=sys.stderr)
else:
	inp = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

	def debug(*args):
		pass
for _ in range(int(inp())):
	n = int(inp())
	A = [*map(int, inp().split())]
	even = odd = 0
	for (i, a) in enumerate(A):
		if i & 1:
			odd += a
		else:
			even += a
	diff = even - odd
	if diff & 1:
		print('NO')
	else:
		diff = diff // 2
		cand = []
		if diff:
			for i in range(n - 1):
				if A[i] + ((i & 1) * 2 - 1) * diff == A[i + 1]:
					cand.append(i)
		swapped = False
		success = True
		x = 0
		for (i, a) in enumerate(A + [0]):
			x = a - x
			if x < 0:
				debug(x, diff)
				if abs(x) > abs(diff):
					swap = max([-1] + [ind for ind in cand if ind < i])
				else:
					swap = max([-1] + [ind for ind in cand if ind <= i])
				if swap >= 0:
					(A[swap], A[swap + 1]) = (A[swap + 1], A[swap])
				else:
					success = False
				swapped = True
				break
		if swapped and success:
			x = 0
			for (i, a) in enumerate(A + [0]):
				x = a - x
				if x < 0:
					success = False
					break
		if success:
			print('YES')
		else:
			print('NO')


from sys import stdin, gettrace, stderr
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(input())
	aa = [int(a) for a in input().split()]
	asum = 0
	asums = []
	fneg = n
	for (i, a) in enumerate(aa):
		asum = a - asum
		if asum < 0 and fneg == n:
			fneg = i
		asums.append(asum)
	if asum == 0 and fneg == n:
		print('YES')
		return
	mins = [0] * (n - 2) + [asums[-2], asums[-1]]
	for i in range(-3, -n - 1, -1):
		mins[i] = min(asums[i], mins[i + 2])
	lim = min(fneg + 1, n - 1)
	for i in range(lim):
		sign = (-1) ** (n - 1 - i)
		cval = aa[i] - aa[i + 1]
		if 2 * cval * sign == asum and asums[i] - cval >= 0 and (mins[i + 1] + 2 * cval >= 0) and (i == n - 2 or mins[i + 2] - 2 * cval >= 0):
			print('YES')
			return
	print('NO')

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


def solve(n, arr):
	if n == 1:
		return 'YES'
	if n == 2:
		if arr[0] == arr[1]:
			return 'YES'
		else:
			return 'NO'
	inv = arr[::-1]
	x1 = [arr[0]]
	x2 = [arr[n - 1]]
	for i in range(1, n - 1):
		x1.append(arr[i] - x1[-1])
	for i in range(n - 2, 0, -1):
		x2.append(arr[i] - x2[-1])
	x2 = x2[::-1]
	gt1 = [False for i in range(n - 1)]
	gt2 = [False for i in range(n - 1)]
	for i in range(n - 1):
		if x1[i] >= 0:
			gt1[i] = True
		else:
			break
	for i in range(n - 2, -1, -1):
		if x2[i] >= 0:
			gt2[i] = True
		else:
			break
	d = arr[n - 1] - x1[n - 2]
	if d == 0 and gt2[0]:
		return 'YES'
	for i in range(n - 1):
		cur = x1[i] - x2[i] + 2 * (arr[i + 1] - arr[i])
		if cur == 0 and (i == 0 or gt1[i - 1]) and (i == n - 2 or gt2[i + 1]) and (x1[i] + (arr[i + 1] - arr[i]) >= 0):
			return 'YES'
	return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
uu = t
while t > 0:
	t -= 1
	n = fi()
	a = li()
	pre = [[0, 1] for i in range(n + 1)]
	suf = [[0, 1] for i in range(n + 1)]
	c = 0
	for i in range(n):
		pre[i][1] = pre[i - 1][1]
		if c > a[i]:
			pre[i][1] = 0
		pre[i][0] = c
		c = a[i] - c
	pre[n][0] = c
	c = 0
	for i in range(n - 1, -1, -1):
		suf[i][1] = suf[i + 1][1]
		if c > a[i]:
			suf[i][1] = 0
		suf[i][0] = c
		c = a[i] - c
	suf[n][0] = c
	c = 0
	if pre[n - 1][1] and suf[0][1] and (pre[n][0] == 0) and (suf[n][0] == 0):
		print('YES')
		continue
	for i in range(1, n):
		c = pre[i - 2][1] & suf[i + 1][1]
		if pre[i - 1][0] > a[i] or suf[i][0] > a[i - 1] or pre[i - 1][0] + a[i - 1] - suf[i][0] > a[i] or (suf[i][0] + a[i] - pre[i - 1][0] > a[i - 1]):
			c = 0
		if c == 1:
			break
	print('YES' if c else 'NO')


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = int(1000000000.0) + 7
MAX = int(200000.0) + 1

def solve():
	n = int(input())
	arr = array()
	pre = [0 for i in range(n + 1)]
	suf = [0 for i in range(n + 1)]
	cnt = 0
	for i in range(n):
		if pre[i] <= arr[i] and pre[i] != -1:
			pre[i + 1] = arr[i] - pre[i]
		else:
			pre[i + 1] = -1
	for i in range(n - 1, 0, -1):
		if suf[i + 1] <= arr[i] and suf[i + 1] != -1:
			suf[i] = arr[i] - suf[i + 1]
		else:
			suf[i] = -1
	for i in range(n - 2, -1, -1):
		if pre[i] == -1 or suf[i + 2] == -1:
			continue
		if arr[i] - pre[i] == arr[i + 1] - suf[i + 2] >= 0 or arr[i + 1] - pre[i] == arr[i] - suf[i + 2] >= 0:
			print('YES')
			return
	print('NO')

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

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

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

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)
primes = [1 for i in range(MAX)]

def sieve():
	global primes
	primes[0] = primes[1] = 0
	i = 2
	while i <= MAX ** 0.5:
		j = i * i
		while primes[i] and j < MAX:
			if j % i == 0:
				primes[j] = 0
			j += i
		i += 1

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

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


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

def main():
	t = int(stdin.readline())
	for tt in range(1, t + 1):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		dp_l = [-1 for _ in range(n)]
		dp_l[0] = arr[0]
		for i in range(1, n):
			dp_l[i] = arr[i] - dp_l[i - 1]
			if dp_l[i] < 0:
				break
		dp_r = [-1 for _ in range(n)]
		dp_r[n - 1] = arr[n - 1]
		for i in range(n - 2, -1, -1):
			dp_r[i] = arr[i] - dp_r[i + 1]
			if dp_r[i] < 0:
				break
		if dp_l[n - 1] == 0:
			stdout.write('YES\n')
			continue
		is_found = False
		for i in range(n - 1):
			p = []
			if i > 0:
				if dp_l[i - 1] < 0:
					continue
				p.append(dp_l[i - 1])
			p.append(arr[i + 1])
			p.append(arr[i])
			if i < n - 2:
				if dp_r[i + 2] < 0:
					continue
				p.append(dp_r[i + 2])
			sm = p[0]
			for j in range(1, len(p)):
				sm = p[j] - sm
				if sm < 0:
					break
			if sm == 0:
				is_found = True
				break
		if is_found:
			stdout.write('YES\n')
		else:
			stdout.write('NO\n')
main()


import sys
import math

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

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

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

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

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod
t = II()
for q in range(t):
	n = II()
	a = LI()
	pref = [0 for i in range(n)]
	suf = [0 for i in range(n)]
	pref[0] = a[0]
	boo = False
	for i in range(1, n):
		if pref[i - 1] < 0 or a[i] < pref[i - 1]:
			pref[i] = -1
		else:
			pref[i] = a[i] - pref[i - 1]
	suf[-1] = a[-1]
	for i in range(n - 2, -1, -1):
		if suf[i + 1] < 0 or a[i] < suf[i + 1]:
			suf[i] = -1
		else:
			suf[i] = a[i] - suf[i + 1]
	if suf[0] == 0 or pref[-1] == 0:
		boo = True
	pref = [0] + pref
	suf += [0]
	for i in range(n - 1):
		if pref[i] >= 0 and suf[i + 2] >= 0 and (a[i + 1] >= pref[i]) and (a[i + 1] - pref[i] == a[i] - suf[i + 2]):
			boo = True
			break
	print('YES' if boo else 'NO')


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from functools import *
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')

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] > self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

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

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None

def judge(a):
	res = [0]
	n = len(a)
	f = True
	for x in a:
		res.append(x - res[-1])
		if res[-1] < 0:
			f = False
			break
	if f:
		return 1
	for i in range(n - 1):
		(a[i], a[i + 1]) = (a[i + 1], a[i])
		res = [0]
		f = True
		for x in a:
			res.append(x - res[-1])
			if res[-1] < 0:
				f = False
				break
		if f:
			print(a, res)
			(a[i], a[i + 1]) = (a[i + 1], a[i])
			return 1
		(a[i], a[i + 1]) = (a[i + 1], a[i])
	return 0
from random import randint

def build(n):
	f = False
	while not f:
		a = []
		for i in range(n - 1):
			a.append(randint(1, 10))
		x = 0
		for i in range(n - 1):
			x = a[i] - x
		a.append(x)
		if a[-1] > 0:
			f = True
	return a
t = N()
for i in range(t):
	n = N()
	a = RLL()
	s = 0
	res = []
	pre = [0]
	for i in range(n):
		if i & 1:
			res.append(-a[i])
		else:
			res.append(a[i])
		pre.append(a[i] - pre[-1])
	s = pre[-1]
	ans = False
	mi = [0] * n
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			mi[i] = pre[-1]
		elif i == n - 2:
			mi[i] = pre[-2]
		else:
			mi[i] = min(mi[i + 2], pre[i + 1])
	if s == 0:
		if all((x >= 0 for x in pre)):
			ans = True
	else:
		for i in range(n - 1):
			cur = a[i] - a[i + 1] if not n - 1 - i & 1 else a[i + 1] - a[i]
			if s - 2 * cur == 0:
				if a[i + 1] - pre[i] >= 0 and a[i] - a[i + 1] + pre[i] >= 0:
					if (i >= n - 2 or mi[i + 2] >= 2 * (a[i] - a[i + 1])) and (i >= n - 3 or mi[i + 3] >= 2 * (a[i + 1] - a[i])):
						ans = True
						break
			if pre[i + 1] < 0:
				break
	ans = 'YES' if ans else 'NO'
	print(ans)


from sys import stdin
input = stdin.readline

def pyk(l):
	res = [-1] * len(l)
	res[0] = 0
	for i in range(1, len(l)):
		res[i] = l[i - 1]
		l[i] -= l[i - 1]
		if l[i] < 0:
			break
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(a) for a in input().split()]
	from_left = pyk(l[:])
	from_right = pyk(l[::-1])[::-1]
	okok = False
	for (a, b, x, y) in zip(l[:-1], l[1:], from_left[:-1], from_right[1:]):
		if x != -1 and y != -1:
			if a - x >= 0 and a - x == b - y:
				okok = True
				break
			if b - x >= 0 and a - y == b - x:
				okok = True
				break
	print('YES' if okok else 'NO')


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = ['NO'] * T
INF = 2 * 10 ** 9 + 7
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	if N & 1:
		A.append(0)
		N += 1
	B = A[:]
	for i in range(1, N):
		B[i] -= B[i - 1]
	if all((b >= 0 for b in B)) and B[-1] == 0:
		Ans[qu] = 'YES'
		continue
	Beven = [B[i] for i in range(N) if i % 2 == 0]
	Bodd = [B[i] for i in range(N) if i % 2 == 1]
	for l in range(len(Beven) - 2, -1, -1):
		Beven[l] = min(Beven[l], Beven[l + 1])
	for l in range(len(Bodd) - 2, -1, -1):
		Bodd[l] = min(Bodd[l], Bodd[l + 1])
	Beven.append(INF)
	Bodd.append(INF)
	for i in range(N - 1):
		if i and B[i - 1] < 0:
			break
		d = A[i + 1] - A[i]
		if B[i] + d >= 0:
			if i & 1:
				if B[-1] + 2 * d:
					continue
				if Bodd[(i + 2) // 2] + 2 * d >= 0 and Beven[(i + 1) // 2] - 2 * d >= 0:
					Ans[qu] = 'YES'
					break
			else:
				if B[-1] - 2 * d:
					continue
				if Beven[(i + 2) // 2] + 2 * d >= 0 and Bodd[(i + 1) // 2] - 2 * d >= 0:
					Ans[qu] = 'YES'
					break
print('\n'.join(Ans))


from __future__ import division, print_function
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
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))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

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 testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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
inf = pow(10, 20)
mod = 10 ** 9 + 7

def do(b, n):
	ans = True
	for i in range(n - 1):
		if i == n - 2:
			if b[i] != b[i + 1]:
				ans = False
		elif b[i] <= b[i + 1]:
			b[i + 1] -= b[i]
		else:
			ans = False
	return ans

def chck(a):
	ans = False
	b = deepcopy(a)
	n = len(a)
	ans = ans | do(b, n)
	b = deepcopy(a)
	(b[0], b[1]) = (b[1], b[0])
	ans = ans | do(b, n)
	b = deepcopy(a)
	(b[n - 1], b[n - 2]) = (b[n - 2], b[n - 1])
	ans = ans | do(b, n)
	return ans

def solve(case):
	n = int(inp())
	b = lis()
	if n == 2:
		if b[0] == b[1]:
			print('YES')
		else:
			print('NO')
		return
	if chck(b):
		print('YES')
		return
	l = deepcopy(b)
	left = [0] * n
	left[0] = 1
	for i in range(1, n - 1):
		if l[i] >= l[i - 1]:
			l[i] -= l[i - 1]
			left[i] = 1 and left[i - 1]
		else:
			left[i] = 0
	r = deepcopy(b)
	right = [0] * n
	right[n - 1] = 1
	for i in range(n - 2, 0, -1):
		if r[i] >= r[i + 1]:
			r[i] -= r[i + 1]
			right[i] = 1 and right[i + 1]
		else:
			right[i] = 0
	ans = False
	for i in range(n - 3):
		if left[i] and right[i + 3] and (b[i + 2] >= l[i]) and (b[i + 1] >= r[i + 3]) and (b[i + 2] - l[i] == b[i + 1] - r[i + 3]):
			ans = True
	print('YES' if ans else 'NO')
testcase(int(inp()))


import sys, bisect
input = sys.stdin.readline
ans = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	koutai = [a[i] for i in range(n)]
	for i in range(1, n):
		koutai[i] -= koutai[i - 1]
	even = [koutai[i] for i in range(n)]
	odd = [koutai[i] for i in range(n)]
	for i in range(n):
		if i % 2:
			even[i] = 10 ** 17
		else:
			odd[i] = 10 ** 17
	right_min_even = [even[i] for i in range(n)]
	for i in range(n - 2, -1, -1):
		right_min_even[i] = min(right_min_even[i], right_min_even[i + 1])
	right_min_odd = [odd[i] for i in range(n)]
	for i in range(n - 2, -1, -1):
		right_min_odd[i] = min(right_min_odd[i], right_min_odd[i + 1])
	tmp_min = 10 ** 17
	tmp_ans = 'NO'
	if koutai[-1] == 0 and min(koutai) == 0:
		tmp_ans = 'YES'
	for i in range(n - 1):
		up = a[i + 1] - a[i]
		last = koutai[-1]
		if (n - 1 - i) % 2 == 0:
			last += 2 * up
		else:
			last -= 2 * up
		if koutai[i] + up >= 0 and tmp_min >= 0 and (last == 0):
			if i % 2 == 0:
				minus_odd = right_min_odd[i + 1] - 2 * up
				up_even = right_min_even[i + 1] + 2 * up
				if minus_odd >= 0 and up_even >= 0:
					tmp_ans = 'YES'
			else:
				up_odd = right_min_odd[i + 1] + 2 * up
				minus_even = right_min_even[i + 1] - 2 * up
				if up_odd >= 0 and minus_even >= 0:
					tmp_ans = 'YES'
		if koutai[i] < 0:
			break
	ans.append(tmp_ans)
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	fow = [0]
	back = [0]
	ind1 = []
	ind2 = []
	for j in range(n):
		fow.append(b[j] - fow[-1])
		if fow[-1] < 0:
			ind1.append(j)
		back.append(b[n - 1 - j] - back[-1])
		if back[-1] < 0:
			ind2.append(n - j - 1)
	fow.pop(0)
	back.reverse()
	back.pop()
	pre = [j for j in back]
	suf = [j for j in fow]
	for j in range(n):
		if j - 2 >= 0:
			pre[j] = min(pre[j], pre[j - 2])
		if n - j + 1 < n:
			suf[n - j - 1] = min(suf[n - j - 1], suf[n - j + 1])
	poss = 0
	for j in range(n):
		if j == 0:
			if fow[-1] == 0 and ind1 == []:
				poss = 1
				break
			if back[0] == 0 and ind2 == []:
				poss = 1
				break
		else:
			pr = b[j] - b[j - 1]
			q = j % 2
			r = (n - 1) % 2
			if q == r:
				res1 = fow[-1] - 2 * pr
			else:
				res1 = fow[-1] + 2 * pr
			if res1 == 0 and fow[j - 1] + pr >= 0 and (suf[j] >= 2 * pr) and (1 if j + 1 < n and suf[j + 1] >= -2 * pr or j + 1 >= n else 0):
				if ind1 == []:
					poss = 1
					break
				elif ind1[0] >= j - 1:
					poss = 1
					break
			r = 0
			if q == r:
				res1 = back[0] - 2 * pr
			else:
				res1 = back[0] + 2 * pr
			if res1 == 0 and pre[j - 1] >= -2 * pr and (back[j] - pr >= 0) and (1 if j - 2 >= 0 and pre[j - 2] >= 2 * pr or j - 2 < 0 else 0):
				if ind2 == []:
					poss = 1
					break
				elif ind2[0] < j + 1:
					poss = 1
					break
	if poss:
		print('YES')
	else:
		print('NO')


import sys, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def check(lst):
	remainder = lst[0]
	for x in lst[1:]:
		remainder = x - remainder
		if remainder < 0:
			return False
	else:
		if remainder == 0:
			return True
	return False

def remainder_arr(lst):
	remainder = lst[0]
	remainders = [0, lst[0]]
	faulty = False
	for x in lst[1:]:
		remainder = x - remainder
		if faulty:
			remainder = -1
		remainders.append(remainder)
		if remainder < 0:
			faulty = True
	return remainders

def solve_(arr, reverse=False):
	if check(arr):
		log('no swap')
		return 'YES'
	remainder = arr[0]
	for (i, x) in enumerate(arr[1:], start=1):
		remainder = x - remainder
		if remainder < 0:
			(arr[i], arr[i - 1]) = (arr[i - 1], arr[i])
			if check(arr):
				log('left swap')
				return 'YES'
			(arr[i], arr[i - 1]) = (arr[i - 1], arr[i])
			break
	(arr[-2], arr[-1]) = (arr[-1], arr[-2])
	if check(arr):
		log('end swap')
		return 'YES'
	(arr[-2], arr[-1]) = (arr[-1], arr[-2])
	xrr = remainder_arr(arr)
	yrr = remainder_arr(arr[::-1])[::-1]
	log(xrr)
	log(yrr)
	remainder = 0
	for (i, (x, y)) in enumerate(zip(arr, arr[1:])):
		if x - remainder > y:
			break
		new_remainder = x - (y - remainder)
		log(x, y, new_remainder, yrr[i + 2])
		if new_remainder >= 0 and yrr[i + 2] == new_remainder:
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
			if check(arr):
				log('advanced swap')
				return 'YES'
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		remainder = x - remainder
	if not reverse:
		log('reversing')
		return solve_(arr[::-1], reverse=True)
	return 'NO'
for case_num in range(int(input())):
	k = int(input())
	lst = list(map(int, input().split()))
	res = solve(lst)
	print(res)


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	for t in range(mint()):
		n = mint()
		a = list(mints())
		p = [-1] * (n + 1)
		p[0] = 0
		s = 0
		for i in range(n):
			p[i + 1] = a[i] - p[i]
			if p[i + 1] < 0:
				break
		if p[n] == 0:
			print('YES')
			continue
		for i in range(n - 1, 0, -1):
			if p[i - 1] >= 0 and a[i - 1] - s >= 0 and (a[i - 1] - s == a[i] - p[i - 1]):
				print('YES')
				break
			s1 = a[i] - s
			if s1 < 0:
				print('NO')
				break
			s = s1
		else:
			print('NO')
solve()


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = a[:]
		f = 0
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				f = 1
				break
			a[i + 1] = a[i + 1] - a[i]
		if f == 0 and a[n - 1] == 0:
			print('YES')
			continue
		ans = 'NO'
		pre = [0] * n
		suf = [0] * n
		pre[0] = b[0]
		for i in range(1, n):
			if b[i] >= pre[i - 1]:
				pre[i] = b[i] - pre[i - 1]
			else:
				pre[i] = inf
		suf[-1] = b[-1]
		for i in range(n - 2, -1, -1):
			if b[i] >= suf[i + 1]:
				suf[i] = b[i] - suf[i + 1]
			else:
				suf[i] = inf
		for i in range(n - 1):
			(l, r) = (0, 0)
			if i > 0:
				l = pre[i - 1]
			if i < n - 2:
				r = suf[i + 2]
			if b[i] >= r and b[i + 1] >= l and (b[i] - r == b[i + 1] - l):
				ans = 'YES'
				break
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


def ke(x: list):
	y = x.copy()
	for o in range(0, len(y) - 1):
		if y[o] > y[o + 1]:
			return False
		else:
			y[o + 1] -= y[o]
			y[o] = 0
	if y[len(y) - 1] == 0:
		return True
	return False
t = int(input())
for cas in range(0, t):
	n = int(input())
	v = list(map(int, input().split()))
	if ke(v):
		print('YES')
		continue
	if n == 1:
		print('NO')
		continue
	z = v.copy()
	(z[0], z[1]) = (z[1], z[0])
	if ke(z):
		print('YES')
		continue
	z = v.copy()
	(z[n - 2], z[n - 1]) = (z[n - 1], z[n - 2])
	if ke(z):
		print('YES')
		continue
	zuo = [0] * n
	you = [0] * n
	z = v.copy()
	zuo[0] = v[0]
	for i in range(1, n):
		if zuo[i - 1] == -1 or z[i - 1] > z[i]:
			zuo[i] = -1
		else:
			z[i] -= z[i - 1]
			z[i - 1] = 0
			zuo[i] = z[i]
	z = v.copy()
	you[n - 1] = v[n - 1]
	for i in range(n - 2, -1, -1):
		if you[i + 1] == -1 or z[i + 1] > z[i]:
			you[i] = -1
		else:
			z[i] -= z[i + 1]
			z[i + 1] = 0
			you[i] = z[i]
	z = v.copy()
	xing = False
	for i in range(1, n - 2):
		if zuo[i - 1] != -1 and you[i + 2] != -1 and ke([zuo[i - 1], z[i + 1], z[i], you[i + 2]]):
			xing = True
			break
	if xing:
		print('YES')
	else:
		print('NO')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(50001)]
pp = []

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

def check(arr):
	n = len(arr)
	prev = 0
	ch = True
	for i in range(n):
		arr[i] -= prev
		if arr[i] < 0:
			arr[i] = 0
			ch = False
		prev = arr[i]
	if arr[-1] != 0:
		ch = False
	return ch
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = [0] * n
	s = [0] * n
	p1 = [0] * n
	s1 = [0] * n
	prev = 0
	ch = 1
	t = 1
	for i in range(n):
		p[i] = a[i] - prev
		if p[i] < 0:
			ch = 0
			t = 0
			p[i] = 0
		prev = p[i]
		if t:
			p1[i] = 1
	prev = 0
	t = 1
	for i in range(n - 1, -1, -1):
		s[i] = a[i] - prev
		if s[i] < 0:
			s[i] = 0
			ch = 0
			t = 0
		prev = s[i]
		if t:
			s1[i] = 1
	if ch == 1 and (p[-1] == 0 or s[0] == 0):
		print('YES')
		continue
	b = 0
	for i in range(n - 1):
		temp = []
		d = 1
		if i > 0:
			temp.append(p[i - 1])
			if p1[i - 1] == 0:
				d = 0
		temp.append(a[i + 1])
		temp.append(a[i])
		if i < n - 2:
			temp.append(s[i + 2])
			if s1[i + 2] == 0:
				d = 0
		ch = check(temp)
		if ch and d:
			b = 1
			print('YES')
			break
	if b == 0:
		print('NO')


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	l = [-1] * N
	b = 0
	f = 1
	for i in range(N):
		x = X[i]
		if b > x:
			f = 0
			break
		b = x - b
		l[i] = b
	if f and b == 0:
		print('YES')
		continue
	l2 = [-1] * N
	b = 0
	for i in range(N - 1, -1, -1):
		x = X[i]
		if b > x:
			break
		b = x - b
		l2[i] = b
	f = 0
	for i in range(N - 1):
		(c, b) = (X[i], X[i + 1])
		if i == 0:
			a = 0
		else:
			a = l[i - 1]
		if i == N - 2:
			d = 0
		else:
			d = l2[i + 2]
		if a == -1 or d == -1:
			continue
		if b - a == c - d and b >= a:
			print('YES')
			f = 1
			break
	if not f:
		print('NO')


def main():
	cases = int(input())
	ans_list = []
	for _ in range(cases):
		n = int(input())
		arr = list(map(int, input().split(' ')))
		prefix = [float('inf') for i in range(n + 1)]
		prefix[1] = arr[0]
		cur = arr[0]
		for i in range(1, n):
			cur = arr[i] - cur
			if cur < 0:
				break
			prefix[i + 1] = cur
		suffix = [float('inf') for i in range(n)]
		suffix[n - 1] = arr[-1]
		cur = arr[-1]
		for i in range(n - 2, -1, -1):
			cur = arr[i] - cur
			if cur < 0:
				break
			suffix[i] = cur
		if prefix[n] == 0:
			ans = 'YES'
		else:
			ans = 'NO'
		if n != 2:
			for i in range(n - 1):
				if ans == 'YES':
					break
				if i == 0:
					if arr[0] - suffix[2] == arr[1]:
						ans = 'YES'
				elif i == n - 2:
					if arr[i + 1] - prefix[i] == arr[i]:
						ans = 'YES'
				else:
					res_1 = arr[i + 1] - prefix[i]
					res_2 = arr[i] - suffix[i + 2]
					if res_1 >= 0 and res_1 == res_2:
						ans = 'YES'
		ans_list.append(ans)
	print('\n'.join(ans_list))
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')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = [a[0]]
	for i in range(1, n):
		s.append(a[i] - s[-1])
	mi0 = mi1 = 10 ** 16
	mia0 = []
	mia1 = []
	for i in range(n - 1, -1, -1):
		v = s[i]
		if i % 2 == 0:
			mi0 = min(mi0, v)
		else:
			mi1 = min(mi1, v)
		mia0.append(mi0)
		mia1.append(mi1)
	mia0.reverse()
	mia1.reverse()
	mia0.append(10 ** 16)
	mia1.append(10 ** 16)
	if min(mi0, mi1) >= 0 and s[-1] == 0:
		print('YES')
	else:
		poss = False
		for i in range(n - 1):
			dv = -2 * (a[i] - a[i + 1])
			if (i % 2 == 0) == (n % 2 == 0):
				ne = s[-1] - dv
			else:
				ne = s[-1] + dv
			if ne == 0:
				if i % 2 == 1:
					if mia0[i] - dv >= 0 and min(mia1[i + 1] + dv, s[i] + dv // 2) >= 0:
						poss = True
						break
				elif mia1[i] - dv >= 0 and min(mia0[i + 1] + dv, s[i] + dv // 2) >= 0:
					poss = True
					break
			if s[i] < 0:
				break
		print('YES' if poss else 'NO')


import os, sys
from io import BytesIO, IOBase
from math import inf

def solve(n, a):
	x = a[:]
	for i in range(1, n):
		a[i] -= a[i - 1]
	val = a[-1]
	if not val:
		return 'NO' if min(a) < 0 else 'YES'
	if abs(a[-1]) & 1:
		return 'NO'
	mini = [a[-1], a[-2]]
	for i in range(-3, -n - 1, -1):
		mini.append(min(mini[-2], a[i]))
	mini.reverse()
	mini.append(inf)
	for i in range(n - 1):
		if n - 1 - i & 1:
			if x[i] == x[i + 1] - val // 2 and mini[i + 2] >= -val and (mini[i + 1] >= val) and (a[i] >= -val // 2):
				return 'YES'
		elif x[i] == x[i + 1] + val // 2 and mini[i + 2] >= val and (mini[i + 1] >= -val) and (a[i] >= val // 2):
			return 'YES'
		if a[i] < 0:
			break
	return 'NO'

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		print(solve(n, a))
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')
main()


def can_clean(case):
	cur_num = case[0]
	for i in range(1, len(case)):
		next_num = case[i] - cur_num
		if next_num < 0:
			return False
		cur_num = next_num
	return True if cur_num == 0 else False
for t in range(int(input())):
	n = int(input())
	aa = [int(x) for x in input().split()]
	fwd = {}
	have_printed = False
	bwd = {}
	for i in range(len(aa)):
		ai = aa[i]
		if i == 0:
			fwd[i] = ai
		else:
			next_val = ai - fwd[i - 1]
			if next_val < 0:
				break
			fwd[i] = next_val
	for i in range(len(aa) - 1, -1, -1):
		ai = aa[i]
		if i == len(aa) - 1:
			bwd[i] = ai
		else:
			next_val = ai - bwd[i + 1]
			if next_val < 0:
				break
			bwd[i] = next_val
	if len(bwd) == len(aa) and bwd[0] == 0:
		print('YES')
		continue
	for i in range(len(aa) - 1):
		swap_pos = (i, i + 1)
		if i == 0:
			case = [aa[i + 1], aa[i], bwd.get(i + 2, -1)]
		elif i + 1 == len(aa) - 1:
			case = [fwd.get(i - 1, -1), aa[i + 1], aa[i]]
		else:
			case = [fwd.get(i - 1, -1), aa[i + 1], aa[i], bwd.get(i + 2, -1)]
		if case[0] < 0 or case[-1] < 0:
			continue
		if can_clean(case):
			print('YES')
			have_printed = True
			break
	if not have_printed:
		print('NO')


import collections, functools, sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	l = [0] * (n + 1)
	r = [0] * (n + 1)
	for i in range(n):
		l[i + 1] = -1 if l[i] < 0 else a[i] - l[i]
	for i in range(n - 1, -1, -1):
		r[i] = -1 if r[i + 1] < 0 else a[i] - r[i + 1]
	if l[-1] == 0 or r[0] == 0:
		print('YES')
		continue
	for i in range(n - 1):
		left = l[i]
		right = r[i + 2]
		if left < 0 or right < 0:
			continue
		ele1 = a[i]
		ele2 = a[i + 1]
		x = ele2 - left
		if x >= 0:
			y = ele1 - x
			if y == right:
				print('YES')
				break
		x = ele1 - right
		if x >= 0:
			y = ele2 - x
			if y == left:
				print('YES')
				break
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	l = [-1] * N
	l[0] = a[0]
	for i in range(N - 1):
		if l[i] >= 0:
			l[i + 1] = a[i + 1] - l[i]
	r = [-1] * N
	r[-1] = a[-1]
	for i in range(N - 1, 0, -1):
		if r[i] >= 0:
			r[i - 1] = a[i - 1] - r[i]
	if l[-1] == r[0] == 0:
		print('YES')
		continue
	for i in range(N - 1):
		(x, y, z, w) = (0, a[i + 1], a[i], 0)
		if i - 1 >= 0:
			x = l[i - 1]
		if i + 2 < N:
			w = r[i + 2]
		if y - x == z - w and x >= 0 and (w >= 0) and (x <= y) and (w <= z):
			print('YES')
			break
	else:
		print('NO')


from sys import stdin, stdout

def cleaning(n, a_a):
	l_a = [-1] * n
	r_a = [-1] * n
	l_a[0] = a_a[0]
	for i in range(1, n):
		if a_a[i] < l_a[i - 1]:
			break
		l_a[i] = a_a[i] - l_a[i - 1]
	if l_a[n - 1] == 0:
		return 'YES'
	r_a[n - 1] = a_a[n - 1]
	for i in range(n - 2, -1, -1):
		if a_a[i] < r_a[i + 1]:
			break
		r_a[i] = a_a[i] - r_a[i + 1]
	for i in range(0, n - 1):
		r = a_a[i]
		l = a_a[i + 1]
		if i > 0:
			if l_a[i - 1] < 0:
				continue
			l -= l_a[i - 1]
		if i + 2 < n:
			if r_a[i + 2] < 0:
				continue
			r -= r_a[i + 2]
		if 0 <= l == r >= 0:
			return 'YES'
	return 'NO'
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a_a = list(map(int, stdin.readline().split()))
	r = cleaning(n, a_a)
	stdout.write(r + '\n')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	suok = [True]
	sulft = [0]
	for i in range(n - 1, -1, -1):
		if not suok[-1] or a[i] < sulft[-1]:
			suok.append(False)
			sulft.append(0)
		else:
			suok.append(True)
			sulft.append(a[i] - sulft[-1])
	a.append(0)
	suok = suok[::-1]
	sulft = sulft[::-1]
	if suok[0] and sulft[0] == 0:
		print('YES')
		continue
	prlft = 0
	win = False
	for i in range(n - 1):
		(a[i], a[i + 1]) = (a[i + 1], a[i])
		if suok[i + 2] and a[i] >= prlft and (a[i + 1] >= a[i] - prlft) and (a[i + 1] - (a[i] - prlft) == sulft[i + 2]):
			win = True
			break
		(a[i], a[i + 1]) = (a[i + 1], a[i])
		if a[i] < prlft:
			break
		prlft = a[i] - prlft
	print('YES' if win else 'NO')


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 0
	vals = []
	b = 1
	for i in a[::-1]:
		p = i - s
		if p < 0:
			b = 0
		s = p
		vals.append(p)
	if vals[-1] == 0:
		if b:
			print('YES')
		else:
			print('NO')
		continue
	vals = vals[::-1]
	p = -1
	for i in range(n):
		if vals[i] < 0:
			p = i
	diff = {}
	b = 0
	for i in range(n - 1):
		val = a[i] - a[i + 1]
		if b % 2 == 0:
			val *= -1
		val *= 2
		b ^= 1
		if val not in diff:
			diff[val] = [i + 1]
			continue
		if diff[val][-1] < p:
			diff[val] = [i + 1]
		elif diff[val][-1] == p:
			diff[val].append(i + 1)
		else:
			continue
	delta = -vals[0]
	if delta not in diff:
		print('NO')
		continue
	p1 = diff[delta][0]
	for i in range(n):
		if i > p1:
			delta = 0
		if i == p1:
			delta //= 2
		if vals[i] + delta < 0:
			break
		delta *= -1
	else:
		print('YES')
		continue
	delta = -vals[0]
	if len(diff[delta]) == 1:
		print('NO')
		continue
	p1 = diff[delta][1]
	for i in range(n):
		if i > p1:
			delta = 0
		if i == p1:
			delta //= 2
		if vals[i] + delta < 0:
			break
		delta *= -1
	else:
		print('YES')
		continue
	print('NO')


import sys
import math
input = sys.stdin.readline

def check(l, n):
	c1 = 1
	l1 = []
	for i in range(n):
		l1.append(l[i])
	for i in range(n - 1):
		if l1[i] > l1[i + 1]:
			c1 = 0
			break
		l1[i + 1] -= l1[i]
		l1[i] = 0
	if c1 == 1 and l1[n - 1] != 0:
		c1 = 0
	return c1
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if n == 1:
		print('NO')
	else:
		l1 = []
		l2 = []
		p = []
		s = [0] * n
		if check(l, n):
			print('YES')
		else:
			for i in range(n):
				l1.append(l[i])
				l2.append(l[i])
			(l1[0], l1[1]) = (l1[1], l1[0])
			if check(l1, n):
				print('YES')
			else:
				(l1[0], l1[1]) = (l1[1], l1[0])
				(l1[n - 1], l1[n - 2]) = (l1[n - 2], l1[n - 1])
				if check(l1, n):
					print('YES')
				else:
					(l1[n - 1], l1[n - 2]) = (l1[n - 2], l1[n - 1])
					p.append(l[0])
					s[n - 1] = l[n - 1]
					for i in range(1, n):
						if p[i - 1] == -1 or l1[i - 1] > l[i]:
							p.append(-1)
						else:
							l1[i] -= l1[i - 1]
							l1[i - 1] = 0
							p.append(l1[i])
					for i in range(n - 2, -1, -1):
						if s[i + 1] == -1 or l2[i + 1] > l2[i]:
							s[i] = -1
						else:
							l2[i] -= l2[i + 1]
							l2[i + 1] = 0
							s[i] = l2[i]
					ch = 0
					for i in range(1, n - 2):
						l3 = [p[i - 1], l[i + 1], l[i], s[i + 2]]
						if p[i - 1] != -1 and s[i + 2] != -1:
							if check(l3, 4):
								ch = 1
								break
					if ch:
						print('YES')
					else:
						print('NO')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = [-1] * (n + 1)
	p[0] = 0
	for i in range(n):
		p[i + 1] = a[i] - p[i]
		if p[i + 1] < 0:
			break
	if p[n] == 0:
		print('YES')
		continue
	s = 0
	for i in range(n - 1, 0, -1):
		if p[i - 1] >= 0 and a[i - 1] - s >= 0 and (a[i - 1] - s == a[i] - p[i - 1]):
			print('YES')
			break
		s1 = a[i] - s
		if s1 < 0:
			print('NO')
			break
		s = s1
	else:
		print('NO')


import sys
input = sys.stdin.readline
b = 10 ** 9 + 1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = [b] * n
	s = [b] * n
	p[0] = a[0]
	curr = p[0]
	for i in range(1, n):
		curr = a[i] - curr
		if curr < 0:
			break
		p[i] = curr
	s[-1] = a[-1]
	curr = s[-1]
	for i in range(n - 2, -1, -1):
		curr = a[i] - curr
		if curr < 0:
			break
		s[i] = curr
	if p[n - 1] == 0:
		flag = 1
	else:
		flag = 0
	if not flag and (not n == 2):
		if a[0] - s[2] == a[1]:
			flag = 1
		elif a[n - 1] - p[n - 3] == a[n - 2]:
			flag = 1
	for i in range(1, n - 2):
		pi = a[i + 1] - p[i - 1]
		si = a[i] - s[i + 2]
		if pi >= 0 and pi == si:
			flag = 1
			break
	if flag:
		print('YES')
		continue
	print('NO')


def solve():
	n = int(input())
	A = [int(t) for t in input().split()]
	origA = A.copy()
	for i in range(n - 1):
		A[i + 1] -= A[i]
	if min(A) >= 0 and A[-1] == 0:
		print('YES')
		return
	rmqs = [RangeQuery(A[::2]), RangeQuery(A[1::2])]
	for i in range(n - 1):
		diff = origA[i + 1] - origA[i]
		r0 = rmqs[i % 2]
		i0 = i // 2
		c0 = r0.query(0, i0) >= 0 and r0[i0] >= -diff and (r0.query(i0 + 1) >= -2 * diff)
		r1 = rmqs[1 - i % 2]
		i1 = (i + 1) // 2
		c1 = r1.query(0, i1) >= 0 and r1.query(i1) >= 2 * diff
		last = A[-1] + (+2 if (n - 1 - i) % 2 == 0 else -2) * diff
		if c0 and c1 and (last == 0):
			print('YES')
			break
	else:
		print('NO')

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self.size = len(data)
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, start, stop=None):
		if stop is None:
			stop = self.size
		if start >= stop:
			return float('inf')
		depth = (stop - start).bit_length() - 1
		return self.func(self._data[depth][start], self._data[depth][stop - (1 << depth)])

	def __getitem__(self, idx):
		return self._data[0][idx]
import sys, os, io
input = lambda : sys.stdin.readline().rstrip('\r\n')
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode('ascii'))
for _ in range(int(input())):
	solve()
os.write(1, stdout.getvalue())


from collections import defaultdict, deque, Counter
import sys
import bisect
import math
input = sys.stdin.readline
mod = 1000000007
t = int(input())
out = []
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	left = [0]
	for i in range(n):
		v = l[i]
		if left[-1] == -1 or v < left[-1]:
			left.append(-1)
		else:
			left.append(v - left[-1])
	right = [0]
	for i in range(n - 1, -1, -1):
		v = l[i]
		if right[-1] == -1 or v < right[-1]:
			right.append(-1)
		else:
			right.append(v - right[-1])
	right.reverse()
	if left[-1] == 0:
		out.append('YES')
		continue
	for i in range(n - 1):
		four = [left[i], l[i + 1], l[i], right[i + 2]]
		if four[0] >= 0 and four[3] >= 0 and (four[1] >= four[0]) and (four[1] - four[0] + four[3] == four[2]):
			out.append('YES')
			break
	else:
		out.append('NO')
print('\n'.join(out))


import io
import os
from math import inf

class SegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		start += self._size
		stop += self._size
		res_left = res_right = self._default
		while start < stop:
			if start & 1:
				res_left = self._func(res_left, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res_right = self._func(self.data[stop], res_right)
			start >>= 1
			stop >>= 1
		return self._func(res_left, res_right)

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Node:

	def __init__(self, minEven, maxEven, minOdd, maxOdd, total, count):
		self.minEven = minEven
		self.maxEven = maxEven
		self.minOdd = minOdd
		self.maxOdd = maxOdd
		self.total = total
		self.count = count

	def __repr__(self):
		return str((self.minEven, self.maxEven, self.minOdd, self.maxOdd, self.total, self.count))
segDefault = Node(inf, -inf, inf, -inf, 0, 0)

def segMap(x, i):
	if i % 2 == 1:
		x *= -1
	return Node(x, x, inf, -inf, float(x), 1)

def segCombine(l, r):
	if l.count == 0:
		return r
	if r.count == 0:
		return l
	if l.count % 2 == 0:
		minEven = min(l.minEven, l.total + r.minEven)
		maxEven = max(l.maxEven, l.total + r.maxEven)
		minOdd = min(l.minOdd, l.total + r.minOdd)
		maxOdd = max(l.maxOdd, l.total + r.maxOdd)
	else:
		minEven = min(l.minEven, l.total + r.minOdd)
		maxEven = max(l.maxEven, l.total + r.maxOdd)
		minOdd = min(l.minOdd, l.total + r.minEven)
		maxOdd = max(l.maxOdd, l.total + r.maxEven)
	total = l.total + r.total
	count = l.count + r.count
	return Node(minEven, maxEven, minOdd, maxOdd, total, count)

def solve(N, A):
	needed = []
	extra = 0
	for x in A:
		extra = x - extra
		needed.append(extra)
	if needed[-1] == 0 and min(needed) >= 0:
		return 'YES'
	segTree = SegmentTree([segMap(x, i) for (i, x) in enumerate(A)], segDefault, segCombine)
	last = segTree.query(0, N).total
	for i in range(N - 1):
		if A[i] == A[i + 1]:
			continue
		if i % 2 == 0:
			if last - 2 * A[i] + 2 * A[i + 1] != 0:
				continue
		elif last + 2 * A[i] - 2 * A[i + 1] != 0:
			continue
		(old1, old2) = (segTree[i], segTree[i + 1])
		segTree[i] = segMap(A[i + 1], i)
		segTree[i + 1] = segMap(A[i], i + 1)
		if False:
			(A[i], A[i + 1]) = (A[i + 1], A[i])
			pref = [0]
			for (j, x) in enumerate(A):
				if j % 2 == 0:
					pref.append(pref[-1] + x)
				else:
					pref.append(pref[-1] - x)
			for j in range(N + 1):
				check = segTree.query(0, j)
				evens = pref[1:j + 1:2]
				odds = pref[2:j + 1:2]
				assert check.total == pref[j]
				assert check.minEven == min(evens, default=inf)
				assert check.maxEven == max(evens, default=-inf)
				assert check.minOdd == min(odds, default=inf)
				assert check.maxOdd == max(odds, default=-inf)
				assert check.count == j == len(evens) + len(odds)
			(A[i], A[i + 1]) = (A[i + 1], A[i])
		res = segTree.query(0, N)
		assert res.total == 0
		if res.minEven >= 0 and -res.maxOdd >= 0:
			return 'YES'
		(segTree[i], segTree[i + 1]) = (old1, old2)
	return 'NO'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
out = []
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	left = [0]
	for i in range(n):
		v = l[i]
		if left[-1] == -1 or v < left[-1]:
			left.append(-1)
		else:
			left.append(v - left[-1])
	right = [0]
	for i in range(n - 1, -1, -1):
		v = l[i]
		if right[-1] == -1 or v < right[-1]:
			right.append(-1)
		else:
			right.append(v - right[-1])
	right.reverse()
	if left[-1] == 0:
		out.append('YES')
		continue
	for i in range(n - 1):
		four = [left[i], l[i + 1], l[i], right[i + 2]]
		if four[0] >= 0 and four[3] >= 0 and (four[1] >= four[0]) and (four[1] - four[0] == four[2] - four[3]):
			out.append('YES')
			break
	else:
		out.append('NO')
print('\n'.join(out))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))

	def check(A):
		B = A.copy()
		for i in range(len(A) - 1):
			if B[i] > B[i + 1]:
				return False
			B[i + 1] -= B[i]
			B[i] = 0
		return B[-1] == 0
	if check(A):
		print('YES')
		continue
	(A[0], A[1]) = (A[1], A[0])
	if check(A):
		print('YES')
		continue
	(A[1], A[0]) = (A[0], A[1])
	(A[-2], A[-1]) = (A[-1], A[-2])
	if check(A):
		print('YES')
		continue
	(A[-1], A[-2]) = (A[-2], A[-1])
	(pre, suf) = ([0] * n, [0] * n)
	B = A.copy()
	pre[0] = B[0]
	for i in range(1, n):
		if pre[i - 1] == -1 or B[i - 1] > B[i]:
			pre[i] = -1
		else:
			B[i] -= B[i - 1]
			B[i - 1] = 0
			pre[i] = B[i]
	B = A.copy()
	suf[-1] = B[-1]
	for i in range(n - 2, -1, -1):
		if suf[i + 1] == -1 or B[i + 1] > B[i]:
			suf[i] = -1
		else:
			B[i] -= B[i + 1]
			B[i + 1] = 0
			suf[i] = B[i]
	for i in range(1, n - 2):
		cur = [pre[i - 1], A[i + 1], A[i], suf[i + 2]]
		if pre[i - 1] == -1 or suf[i + 2] == -1:
			continue
		if check(cur):
			print('YES')
			break
	else:
		print('NO')


from collections import defaultdict

def doTestcase():
	INF = 2000000000
	n = int(input())
	a = list(map(int, input().split()))
	pre_diff = [0] * n
	min_pre = [INF] * n
	suf_diff = [0] * n
	min_suf = [INF] * n
	if sum(a) % 2 != 0:
		return 'NO'
	min_pre[0] = a[0]
	pre_diff[0] = a[0]
	for i in range(1, n):
		pre_diff[i] = a[i] - pre_diff[i - 1]
		min_pre[i] = min(min_pre[i - 1], pre_diff[i])
	min_suf[-1] = a[-1]
	suf_diff[-1] = a[-1]
	for i in range(n - 2, -1, -1):
		suf_diff[i] = a[i] - suf_diff[i + 1]
		min_suf[i] = min(min_suf[i + 1], suf_diff[i])
	if pre_diff[-1] == 0 and min_pre[-1] >= 0:
		return 'YES'
	if suf_diff[0] == 0 and min_suf[0] >= 0:
		return 'YES'
	for i in range(1, n):
		new_pre = a[i]
		new_min_pre = INF
		if i - 2 >= 0:
			new_pre -= pre_diff[i - 2]
			new_min_pre = min(min_pre[i - 2], new_pre)
		new_suf = a[i - 1]
		new_min_suf = INF
		if i + 1 < n:
			new_suf -= suf_diff[i + 1]
			new_min_suf = min(min_suf[i + 1], new_suf)
		if new_min_pre >= 0 and new_min_suf >= 0 and (new_pre == new_suf):
			return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	print(doTestcase())


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
inf = 10 ** 16
md = 10 ** 9 + 7

def toll(aa):
	res = [aa[0]]
	for a in aa[1:]:
		res.append(a - res[-1])
	return res
for _ in range(II()):
	n = II()
	aa = LI()
	ll = toll(aa)
	if ll[-1] == 0 and min(ll) >= 0:
		print('YES')
		continue
	rr = toll(aa[::-1])[::-1]
	e = n - 1
	for (i, l) in enumerate(ll[:-1]):
		if l < 0:
			e = i + 1
			break
	b = 0
	for i in range(n - 1, 0, -1):
		if rr[i] < 0:
			b = i - 1
			break

	def ok(i):
		pre = aa[1] if i == 0 else aa[i + 1] - ll[i - 1]
		suf = aa[n - 2] if i == n - 2 else aa[i] - rr[i + 2]
		return pre == suf and pre >= 0
	for i in range(b, e):
		if ok(i):
			print('YES')
			break
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 10 ** 9 + 7

def solve(_):
	N = getInt()
	A = getInts()
	odds = []
	evens = []
	B = [A[0]]
	for i in range(1, N):
		B.append(A[i] - B[-1])
	min_odd_right = [10 ** 18] * N
	min_even_right = [10 ** 18] * N
	cur_min_even = cur_min_odd = 10 ** 18
	min_odd_left = [10 ** 18] * N
	min_even_left = [10 ** 18] * N
	cur_min_even = cur_min_odd = 10 ** 18
	cme2 = cmo2 = 10 ** 18
	for i in range(N - 1, -1, -1):
		if not i % 2:
			min_even_right[i] = cur_min_even
			cur_min_even = min(B[i], cur_min_even)
		else:
			min_odd_right[i] = cur_min_odd
			cur_min_odd = min(B[i], cur_min_odd)
	for i in range(N):
		if not i % 2:
			min_even_left[i] = cme2
			cme2 = min(B[i], cme2)
		else:
			min_odd_left[i] = cmo2
			cmo2 = min(B[i], cmo2)
	if cur_min_even >= 0 and cur_min_odd >= 0 and (B[0] >= 0) and (B[1] >= 0) and (B[-1] == 0):
		ans.append('YES')
		return
	for i in range(N - 1):
		if min_even_left[i] < 0 or min_odd_left[i] < 0:
			break
		if min_even_left[i + 1] < 0 or min_odd_left[i + 1] < 0:
			break
		diff = A[i + 1] - A[i]
		flag = True
		if B[i] + diff < 0:
			flag = False
		if B[i + 1] - 2 * diff < 0:
			flag = False
		if i % 2 == 0:
			if min_even_right[i] + 2 * diff < 0:
				flag = False
			if min_odd_right[i + 1] - 2 * diff < 0:
				flag = False
		else:
			if min_even_right[i + 1] - 2 * diff < 0:
				flag = False
			if min_odd_right[i] + 2 * diff < 0:
				flag = False
		if (N - 1) % 2 == i % 2 and B[N - 1] + 2 * diff != 0:
			flag = False
		if (N - 1) % 2 == (i + 1) % 2 and B[N - 1] - 2 * diff != 0:
			flag = False
		if flag:
			ans.append('YES')
			return
	ans.append('NO')
	return
ans = []
for _ in range(getInt()):
	solve(_)
print(*ans, sep='\n')


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_left
from math import gcd, log
from collections import Counter
from pprint import pprint
MX = 10 ** 5
p = [i for i in range(MX)]
for i in range(2, MX):
	if p[i] == i:
		for j in range(i * i, MX, i):
			p[j] = i
pm = [i for i in range(2, MX) if p[i] == i]

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	pref = [-1] * n
	pref[0] = arr[0]
	suf = [-1] * n
	suf[-1] = arr[-1]
	for i in range(1, n):
		if pref[i - 1] != -1 and arr[i] >= pref[i - 1]:
			pref[i] = arr[i] - pref[i - 1]
	for i in range(n - 2, -1, -1):
		if suf[i + 1] != -1 and arr[i] >= suf[i + 1]:
			suf[i] = arr[i] - suf[i + 1]
	pref = [0] + pref
	suf.append(0)
	for i in range(n - 1):
		if pref[i] != -1 and suf[i + 2] != -1:
			if arr[i + 1] >= pref[i] and arr[i] >= suf[i + 2] and (arr[i + 1] - pref[i] == arr[i] - suf[i + 2]):
				print('YES')
				return
		if pref[i] == suf[i] == 0:
			print('YES')
			return
	print('NO')
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')
for _ in range(int(input())):
	main()


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

class FastIO(IOBase):

	def __init__(self, file):
		self.newlines = 0
		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()

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

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

def N():
	return int(input())

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

def print_list(l):
	print(''.join(map(str, l)))
from heapq import *
for _ in range(N()):
	n = N()
	a = RLL()
	dp = [-1] * n
	use = set()
	dp[0] = a[0]
	dp[1] = a[1] - a[0]
	if a[0] >= a[1]:
		use.add(a[0] - a[1])
	for i in range(2, n):
		if dp[i - 1] >= 0:
			dp[i] = a[i] - dp[i - 1]
		nex = set()
		for k in use:
			if k <= a[i]:
				nex.add(a[i] - k)
		if dp[i - 2] >= 0:
			t1 = a[i] - dp[i - 2]
			if t1 >= 0:
				if a[i - 1] >= t1:
					nex.add(a[i - 1] - t1)
		use = nex
	if dp[n - 1] == 0 or 0 in use:
		print('YES')
	else:
		print('NO')