Alice and Bob are walking on an infinite straight street. Initially, both are at the position $X=0$ and they start walking in the direction of increasing $X$. After $N$ seconds, they stop. Let's denote Alice's speed and Bob's speed during the $i$-th of these seconds by $A_i$ and $B_i$ respectively.
Sometimes, Alice and Bob walk together, i.e. with the same speed side by side. Let's define the weird distance as the total distance they walk this way. Find this weird distance.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
- The third line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$.

-----Output-----
For each test case, print a single line containing one integer ― the total weird distance. It can be proved that this distance is an integer.

-----Constraints-----
- $1 \le T \le 20$
- $1 \le N \le 10^5$
- $1 \le A_i \le 10^5$ for each valid $i$
- $1 \le B_i \le 10^5$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Subtasks-----
Subtask #1 (30 points): $1 \le N \le 1,000$
Subtask #2 (70 points): original constraints

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

-----Example Output-----
5
0
6

-----Explanation-----
Example case 1:
- Alice and Bob walk side by side during the first second, from $X=0$ to $X=1$.
- Then, Alice starts walking faster than Bob, so they do not walk side by side during second $2$. At the end of second $2$, Alice is at $X=4$, while Bob is at $X=3$.
- During the next second, they again do not walk side by side, but Bob walks faster, so they both end up at $X=7$.
- During the last second, they both walk side by side and the distance they walk is $4$.
- Alice and Bob walk side by side during the $1$-st and $4$-th second and the total weird distance they travel is $1+4=5$.
Example case 2:
- First, Alice walks with speed $2$ and Bob walks with speed $3$, so they do not walk side by side. Alice ends up at $X=2$, while Bob ends up at $X=3$ at the end of the $1$-st second.
- Then, Alice walks with speed $3$ and Bob walks with speed $2$, so they do not walk side by side either.
- Although Alice and Bob both end up at $X=5$ at the end of the $2$-nd second, the weird distance is $0$.
Example case 3: We can see that Alice and Bob always walk together, so the weird distance is $3+3=6$.

Difficulty: EASY

Solutions:
t = int(input())
i = 0
while t > i:
	n = int(input())
	m = list(map(int, input().split()))
	k = list(map(int, input().split()))
	j = 0
	l = 0
	(a, b) = (0, 0)
	while j < n:
		if m[j] == k[j] and a == b:
			l += m[j]
		a += m[j]
		b += k[j]
		j += 1
	print(l)
	i += 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = q = d = 0
	for i in range(n):
		p += a[i]
		q += b[i]
		if p == q and a[i] == b[i]:
			d += a[i]
	print(d)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	a1 = 0
	b1 = 0
	for i in range(n):
		a1 += a[i]
		b1 += b[i]
		if a[i] == b[i] and a1 == b1:
			c += a[i]
	print(c)


n = int(input())
for _ in range(n):
	a = int(input())
	l = [int(x) for x in input().split()]
	l1 = [int(x) for x in input().split()]
	s1 = 0
	s2 = 0
	ans = 0
	for i in range(a):
		if l[i] == l1[i] and s1 == s2:
			s1 += l[i]
			s2 += l1[i]
			ans += l[i]
		else:
			s1 += l[i]
			s2 += l1[i]
	print(ans)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	w = 0
	p = a[0]
	q = b[0]
	if p == q:
		w += p
	for i in range(1, len(a)):
		p += a[i]
		q += b[i]
		if a[i] == b[i] and p == q:
			w += a[i]
	print(w)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	x = 0
	y = 0
	for i in range(n):
		if x == y and a[i] == b[i]:
			s += a[i]
		x += a[i]
		y += b[i]
	print(s)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = 0
	position1 = 0
	position2 = 0
	for i in range(n):
		position1 += a[i]
		position2 += b[i]
		if position1 == position2 and a[i] == b[i]:
			k += a[i]
	print(k)


for tc in range(int(input())):
	n = int(input())
	li1 = list(map(int, input().split(' ')))
	li2 = list(map(int, input().split(' ')))
	walk = 0
	sum1 = 0
	sum2 = 0
	for i in range(n):
		if li1[i] == li2[i] and sum1 == sum2:
			walk += li1[i]
		sum1 += li1[i]
		sum2 += li2[i]
	print(walk)


a = int(input(''))
for i in range(a):
	x = int(input(''))
	A = [int(x) for x in input('').split()]
	B = [int(x) for x in input('').split()]
	c = 0
	d = 0
	e = 0
	for j in range(x):
		c = c + A[j]
		d = d + B[j]
		if c == d and A[j] == B[j]:
			e = e + A[j]
	print(e)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	s1 = 0
	s2 = 0
	for i in range(n):
		s1 += a[i]
		s2 += b[i]
		if a[i] == b[i] and s1 == s2:
			ans += a[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	an = 0
	(pa, pb) = (0, 0)
	for i in range(n):
		if a[i] == b[i] and pa == pb:
			an += a[i]
		pa += a[i]
		pb += b[i]
	print(an)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	total = 0
	da = db = 0
	for (i, j) in zip(a, b):
		if i == j and da == db:
			total += i
		da += i
		db += j
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	disa = 0
	disb = 0
	w = 0
	for i in range(n):
		if disb == disa and a[i] == b[i]:
			w += a[i]
		disa += a[i]
		disb += b[i]
	print(w)


tests = int(input())
for i in range(tests):
	length = int(input())
	alice_arr = list(map(int, input().split()))
	bob_arr = list(map(int, input().split()))
	alice = 0
	bob = 0
	ans = 0
	for j in range(length):
		if alice == bob and alice_arr[j] == bob_arr[j]:
			ans += alice_arr[j]
		alice += alice_arr[j]
		bob += bob_arr[j]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	da = 0
	db = 0
	w = 0
	for j in range(n):
		if da == db and a[j] == b[j]:
			w = w + a[j]
		da = da + a[j]
		db = db + b[j]
	print(w)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (0, 0)
	ans = 0
	for (i, j) in zip(a, b):
		if x == y and i == j:
			ans += i
		x += i
		y += j
	print(ans)


T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	xa = 0
	xb = 0
	distance = 0
	for i in range(N):
		if xa == xb and A[i] == B[i]:
			distance += A[i]
		xa += A[i]
		xb += B[i]
	ans.append(distance)
for i in ans:
	print(i)


try:
	for i in range(int(input())):
		n = int(input())
		ai = list(map(int, input().split()))
		bi = list(map(int, input().split()))
		sa = 0
		sb = 0
		ans = 0
		if n == 1:
			if ai[0] == bi[0]:
				print(ai[0])
			else:
				print(0)
		else:
			for i in range(0, n):
				if i == 0:
					if ai[i] == bi[i]:
						sa = sa + ai[i]
						sb = sb + bi[i]
						ans = ans + ai[i]
				elif sum(ai[:i]) == sum(bi[:i]):
					if ai[i] == bi[i]:
						ans = ans + ai[i]
				else:
					sa = sa + ai[i]
					sb = sb + bi[i]
			print(ans)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	(dia, dib) = (0, 0)
	for i in range(n):
		if a[i] == b[i] and dia == dib:
			count = count + a[i]
		dia = dia + a[i]
		dib = dib + b[i]
	print(count)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(d1, d2) = ([0], [0])
	s1 = s2 = ans = 0
	for i in range(N):
		s1 += A[i]
		s2 += B[i]
		d1.append(s1 * (i + 1))
		d2.append(s2 * (i + 1))
	for i in range(N):
		if d1[i] == d2[i] and d1[i + 1] == d2[i + 1]:
			ans += A[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	s = 0
	c = 0
	d = 0
	for i in range(n):
		if l[i] == m[i] and c == d:
			s += l[i]
		c += l[i]
		d += m[i]
	print(s)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	(da, db) = (0, 0)
	for i in range(n):
		da += a[i]
		db += b[i]
		if a[i] == b[i] and da == db:
			s += a[i]
	print(s)


def fun(a, b, n):
	(s1, s2) = (0, 0)
	w = 0
	for i in range(n):
		if s1 == s2 and a[i] == b[i]:
			w = w + a[i]
		s1 += a[i]
		s2 += b[i]
	return w
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(fun(a, b, n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dista = 0
	distb = 0
	c = 0
	for i in range(n):
		dista += a[i]
		distb += b[i]
		if a[i] == b[i] and dista == distb:
			c += a[i]
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ax = 0
	bx = 0
	wd = 0
	for i in range(0, n):
		ax += a[i]
		bx += b[i]
		if ax == bx:
			if a[i] == b[i]:
				wd += a[i]
	print(wd)


for t in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = 0
	(SUM, Sum) = (0, 0)
	for i in range(N):
		SUM += A[i]
		Sum += B[i]
		if A[i] == B[i]:
			if SUM == Sum:
				C += A[i]
	print(C)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	flag = True
	sa = 0
	sb = 0
	for i in range(n):
		if flag and a[i] == b[i]:
			c += a[i]
		sa += a[i]
		sb += b[i]
		flag = sa == sb
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dis = 0
	curr1 = 0
	curr2 = 0
	for i in range(n):
		if a[i] == b[i] and curr2 == curr1:
			curr1 += a[i]
			curr2 += b[i]
			dis += a[i]
		else:
			curr1 += a[i]
			curr2 += b[i]
	print(dis)


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(x, y) = (0, 0)
	sum = 0
	for i in range(N):
		if A[i] == B[i] and x == y:
			sum += A[i]
		x += A[i]
		y += B[i]
	print(sum)


try:
	for i in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		sa = 0
		sb = 0
		ans = 0
		for i in range(0, n):
			sa = sa + a[i]
			sb = sb + b[i]
			if sa == sb and a[i] == b[i]:
				ans = ans + a[i]
		print(ans)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c, d) = (0, 0)
	s = 0
	for x in range(n):
		if c == d and a[x] == b[x]:
			s = s + a[x]
		c = c + a[x]
		d = d + b[x]
	print(s)


for tc in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	apos = 0
	bpos = 0
	weird = 0
	for i in range(n):
		if apos == bpos and a[i] == b[i]:
			weird += a[i]
		apos += a[i]
		bpos += b[i]
	print(weird)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	a1 = 0
	b1 = 0
	l = []
	for i in range(n):
		a1 += a[i]
		b1 += b[i]
		if a[i] == b[i] and a1 == b1:
			l.append(a[i])
		else:
			pass
	print(sum(l))


for _ in range(int(input())):
	(n, sm1, sm2, smf) = (int(input()), 0, 0, 0)
	(l1, l2) = (list(map(int, input().split())), list(map(int, input().split())))
	for i in range(n):
		if sm1 == sm2 and l1[i] == l2[i]:
			smf += l1[i]
		sm1 += l1[i]
		sm2 += l2[i]
	print(smf)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ya = 0
	yb = 0
	wd = 0
	for i in range(n):
		if ya == yb and a[i] == b[i]:
			wd += a[i]
		ya += a[i]
		yb += b[i]
	print(wd)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = d = r = 0
	for i in range(n):
		if c == d and a[i] == b[i]:
			r += a[i]
		c += a[i]
		d += b[i]
	print(r)


t = int(input())
for ni in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(sa, sb) = (0, 0)
	wa = 0
	for i in range(n):
		if sa == sb and a[i] == b[i]:
			wa = wa + a[i]
		sa = sa + a[i]
		sb = sb + b[i]
	print(wa)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ans = 0
	s1 = 0
	s2 = 0
	for j in range(n):
		if l1[j] == l2[j] and s1 == s2:
			ans += l1[j]
		s1 += l1[j]
		s2 += l2[j]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	alice = list(map(int, input().split()))
	bob = list(map(int, input().split()))
	disa = 0
	disb = 0
	w = 0
	for i in range(n):
		if disb == disa and alice[i] == bob[i]:
			w += alice[i]
		disa += alice[i]
		disb += bob[i]
	print(w)


t = int(input())
for i in range(t):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	answer = 0
	for j in range(n):
		if sum1 == sum2 and a1[j] == b1[j]:
			answer += a1[j]
		sum1 = sum1 + a1[j]
		sum2 = sum2 + b1[j]
	print(answer)


for TC in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(WD, sum1, sum2) = (0, 0, 0)
	for i in range(n):
		if a[i] == b[i] and sum1 == sum2:
			WD = WD + a[i]
		sum1 += a[i]
		sum2 += b[i]
	print(WD)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = a[0] if a[0] == b[0] else 0
	su_a = a[0]
	su_b = b[0]
	for k in range(1, n):
		su_a += a[k]
		su_b += b[k]
		if a[k] == b[k] and su_a == su_b:
			count += a[k]
	print(count)


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	x = 0
	y = 0
	for i in range(n):
		if x == y and a[i] == b[i]:
			ans += a[i]
		x += a[i]
		y += b[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input().split()
	b = input().split()
	Sum = 0
	suma = 0
	sumb = 0
	for i in range(len(a)):
		if i == 0:
			suma += int(a[i])
			sumb += int(b[i])
			if suma == sumb:
				Sum += int(a[i])
		elif suma == sumb:
			suma += int(a[i])
			sumb += int(b[i])
			if suma == sumb:
				Sum += int(a[i])
		else:
			suma += int(a[i])
			sumb += int(b[i])
	print(Sum)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = [a[0]]
	b1 = [b[0]]
	for i in range(n - 1):
		a1.append(a[i + 1] + a1[i])
		b1.append(b[i + 1] + b1[i])
	if a1[0] == b1[0]:
		s = a[0]
	else:
		s = 0
	for i in range(1, n):
		if a1[i] == b1[i] and a1[i - 1] == b1[i - 1]:
			s += abs(a1[i] - a1[i - 1])
	print(s)
	t -= 1


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(' ')]
	(da, db) = (0, 0)
	ans = 0
	for i in range(n):
		if da == db and a[i] == b[i]:
			ans += a[i]
			(da, db) = (da + a[i], da + a[i])
		else:
			(da, db) = (da + a[i], db + b[i])
	print(ans)


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = y = w = 0
	for k in range(n):
		x += a[k]
		y += b[k]
		if a[k] == b[k] and x == y:
			w += a[k]
	print(w)
	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()))
	ax = 0
	bx = 0
	mutual = 0
	for q in range(n):
		if ax == bx and A[q] == B[q]:
			mutual += A[q]
		else:
			ax += A[q]
			bx += B[q]
	print(mutual)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(sum1_a, sum_b) = (0, 0)
	c = 0
	for i in range(n):
		if sum1_a == sum_b:
			if a[i] == b[i]:
				c += a[i]
				sum1_a = 0
				sum_b = 0
			else:
				sum1_a = 0
				sum_b = 0
				sum1_a += a[i]
				sum_b += b[i]
		else:
			sum1_a += a[i]
			sum_b += b[i]
	print(c)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	c = 0
	sumA = 0
	sumB = 0
	for i in range(N):
		sumA += A[i]
		sumB += B[i]
		if sumA == sumB:
			if A[i] == B[i]:
				c += B[i]
	print(c)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(travel_A, travel_B, total) = (0, 0, 0)
	for (a, b) in zip(A, B):
		travel_A += a
		travel_B += b
		if travel_A == travel_B and a == b:
			total += a
	print(total)


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	res = 0
	presum1 = 0
	presum2 = 0
	for i in range(n):
		if arr1[i] == arr2[i] and presum1 == presum2:
			res += arr1[i]
		presum1 += arr1[i]
		presum2 += arr2[i]
	print(res)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(x, y) = (0, 0)
	f = 0
	wd = 0
	for i in range(n):
		if l1[i] == l2[i]:
			if x == y:
				wd = wd + l1[i]
		else:
			x = x + l1[i]
			y = y + l2[i]
	print(wd)


t = int(input())
for _ in range(t):
	n = int(input())
	alice = list(map(int, input().split()))
	bob = list(map(int, input().split()))
	sum_alice = 0
	sum_bob = 0
	common = 0
	for i in range(len(alice)):
		if sum_alice == sum_bob:
			sum_alice += alice[i]
			sum_bob += bob[i]
			if sum_alice == sum_bob:
				common += bob[i]
		else:
			sum_alice += alice[i]
			sum_bob += bob[i]
	print(common)


t = int(input())
for i in range(t):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	distA = 0
	distB = 0
	W_dist = 0
	for i in range(N):
		if distA == distB and A[i] == B[i]:
			W_dist += A[i]
		distA += A[i]
		distB += B[i]
	print(W_dist)


def walk(n, m, o):
	a = 0
	b = 0
	tot = 0
	for i in range(n):
		if m[i] == o[i] and a == b:
			tot += m[i]
		a += m[i]
		b += o[i]
	return tot
t = int(input())
for i in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	o = list(map(int, input().split()))
	print(walk(n, m, o))


for _ in range(int(input())):
	n = int(input())
	Ai = list(map(int, input().split()))
	Bi = list(map(int, input().split()))
	xA = 0
	xB = 0
	wd = 0
	for i in range(n):
		if xA == xB and Ai[i] == Bi[i]:
			wd += Ai[i]
		xA += Ai[i]
		xB += Bi[i]
	print(wd)


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]
	dist_a = 0
	dist_b = 0
	weird = 0
	for j in range(n):
		dist_a = dist_a + a[j]
		dist_b = dist_b + b[j]
		if a[j] == b[j] and dist_a == dist_b:
			weird = weird + a[j]
	print(weird)


for tc in range(int(input())):
	n = int(input())
	list_a = input().split(' ')
	list_a = list(map(int, list_a))
	list_b = input().split(' ')
	list_b = list(map(int, list_b))
	sum = 0
	sum_a = 0
	sum_b = 0
	for i in range(n):
		sum_a += list_a[i]
		sum_b += list_b[i]
		if sum_a == sum_b and list_a[i] == list_b[i]:
			sum += list_a[i]
	print(sum)


t = input()
for c in range(0, int(t)):
	n = input()
	a = input().split()
	b = input().split()
	arr = []
	brr = []
	ca = 0
	cb = 0
	total = 0
	for x in a:
		arr.append(int(x))
	for y in b:
		brr.append(int(y))
	for z in range(0, int(n)):
		ca = ca + arr[z]
		cb = cb + brr[z]
		if ca == cb and arr[z] == brr[z]:
			total = total + arr[z]
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	pa = 0
	pb = 0
	for (x, y) in zip(li1, li2):
		pa = pa + x
		pb = pb + y
		if pa == pb and x == y:
			count += x
	print(count)


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	x = 0
	y = 0
	for j in range(n):
		if a[j] == b[j] and x == y:
			c.append(a[j])
		x += a[j]
		y += b[j]
	print(sum(c))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	alice = 0
	bob = 0
	dist = 0
	for i in range(n):
		if bob == alice and a[i] == b[i]:
			dist += a[i]
		bob += b[i]
		alice += a[i]
	print(dist)


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	count = 0
	position1 = 0
	position2 = 0
	for i in range(N):
		position1 += A[i]
		position2 += B[i]
		if position1 == position2:
			if A[i] == B[i]:
				count += A[i]
	print(count)


for i in range(int(input())):
	n = int(input())
	(dist1, dist2, w) = (0, 0, 0)
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	for (x, y) in zip(l1, l2):
		if x == y:
			if dist1 == dist2:
				w += x
			else:
				dist1 += x
				dist2 += y
		else:
			dist1 += x
			dist2 += y
	print(w)


for _ in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = 0
	b1 = 0
	ans = 0
	for i in range(l):
		if a1 == b1 and a[i] == b[i]:
			ans += a[i]
		a1 += a[i]
		b1 += b[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ra = [0] * n
	x = 0
	for i in range(n):
		ra[i] = x + a[i]
		x = ra[i]
	b = list(map(int, input().split()))
	rb = [0] * n
	y = 0
	for i in range(n):
		rb[i] = y + b[i]
		y = rb[i]
	c = f = 0
	if ra[0] == rb[0]:
		c = a[0]
	for i in range(1, n):
		if ra[i - 1] == rb[i - 1] and a[i] == b[i]:
			c += a[i]
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	sum = 0
	for i in range(n):
		if sum1 == sum2:
			if a[i] == b[i]:
				sum += a[i]
		sum1 += a[i]
		sum2 += b[i]
	print(sum)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xa = 0
	xb = 0
	wd = 0
	for i in range(n):
		if xa == xb and a[i] == b[i]:
			wd += a[i]
		xa += a[i]
		xb += b[i]
	print(wd)


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	distance = 0
	a_dis = 0
	b_dis = 0
	for i in range(n):
		if a_dis == b_dis and a[i] == b[i]:
			distance += a[i]
		a_dis += a[i]
		b_dis += b[i]
	print(distance)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	s = 0
	sum_a = 0
	sum_b = 0
	for i in range(n):
		sum_a += a[i]
		sum_b += b[i]
		if sum_a == sum_b:
			if a[i] == b[i]:
				s += a[i]
	print(s)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	weird = 0
	speed1 = 0
	speed2 = 0
	for j in range(n):
		speed1 += a[j]
		speed2 += b[j]
		if a[j] == b[j] and speed1 == speed2:
			weird += a[j]
	print(weird)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t1 = 0
	t2 = 0
	s = 0
	for i in range(n):
		if t1 == t2 and a[i] == b[i]:
			s = s + a[i]
		t1 = t1 + a[i]
		t2 = t2 + b[i]
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	w = 0
	sa = 0
	sb = 0
	collect = True
	for i in range(n):
		if collect and a[i] == b[i]:
			w += a[i]
		sa += a[i]
		sb += b[i]
		collect = sa == sb
	print(w)


ujju = int(input())
for _ in range(ujju):
	dew = int(input())
	p = list(map(int, input().split()))
	t = list(map(int, input().split()))
	(jay, plu) = (0, 0)
	vis = 0
	for i in range(len(p)):
		if jay == plu and p[i] == t[i]:
			vis += p[i]
		jay += p[i]
		plu += t[i]
	print(vis)


import sys
input = sys.stdin.readline
inf = float('inf')

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

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

def getList(dtype=int, split=True):
	s = getStr()
	if split:
		s = s.split()
	return list(map(dtype, s))
t = getInt()

def solve():
	n = getInt()
	a = getList()
	b = getList()
	diff = res = 0
	for i in range(n):
		if diff == 0 and a[i] == b[i]:
			res += a[i]
		diff += a[i] - b[i]
	print(res)
for _ in range(t):
	solve()


t = int(input())
for k in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	weird_distance = []
	for i in range(n):
		sum1 = sum1 + l1[i]
		sum2 = sum2 + l2[i]
		if sum1 == sum2 and l1[i] == l2[i]:
			weird_distance.append(l1[i])
	print(sum(weird_distance))


T = int(input())
for i in range(T):
	N = int(input())
	A = [int(n) for n in input().split()]
	B = [int(n) for n in input().split()]
	dist_A = 0
	dist_B = 0
	weird_dist = 0
	for i in range(N):
		if dist_A == dist_B and A[i] == B[i]:
			weird_dist += A[i]
		dist_A += A[i]
		dist_B += B[i]
	print(weird_dist)


t = int(input())
while t > 0:
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	s = 0
	s1 = 0
	s2 = 0
	for i in range(n):
		s1 = s1 + l1[i]
		s2 = s2 + l2[i]
		if s1 == s2 and l1[i] == l2[i]:
			s = s + l1[i]
	print(s)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	same = 0
	ax = 0
	bx = 0
	for i in range(n):
		if a[i] == b[i] and ax == bx:
			same += a[i]
		ax += a[i]
		bx += b[i]
	print(same)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(suma, sumb, c) = (0, 0, 0)
	for i in range(n):
		if a[i] == b[i]:
			if suma == sumb:
				c = c + a[i]
		else:
			suma = suma + a[i]
			sumb = sumb + b[i]
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	sa = 0
	sb = 0
	p = 0
	for i in range(n):
		sa += a[i]
		sb += b[i]
		if sa == sb and a[i] == b[i]:
			p += a[i]
	print(p)


T = int(input())
for tc in range(T):
	ans = 0
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	sa = 0
	sb = 0
	for i in range(0, n):
		if A[i] == B[i]:
			if sa == sb:
				ans += A[i]
		sa += A[i]
		sb += B[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	A = 0
	B = 0
	for i in range(n):
		A += a[i]
		B += b[i]
		if A == B and a[i] == b[i]:
			s += a[i]
	print(s)


for i in range(int(input())):
	t = int(input())
	Alice = list(map(int, input().split()))
	Bob = list(map(int, input().split()))
	tot_Alice = 0
	tot_Bob = 0
	total = []
	for (j, k) in zip(Alice, Bob):
		if tot_Alice == tot_Bob and j == k:
			total.append(j)
			tot_Alice += j
			tot_Bob += k
		else:
			tot_Alice += j
			tot_Bob += k
	print(sum(total))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	c1 = 0
	c2 = 0
	for i in range(len(a)):
		c1 += a[i]
		c2 += b[i]
		if c1 == c2:
			if a[i] == b[i]:
				c += a[i]
	print(c)