You have $n$ chains, the $i$-th chain consists of $c_i$ vertices. Vertices in each chain are numbered independently from $1$ to $c_i$ along the chain. In other words, the $i$-th chain is the undirected graph with $c_i$ vertices and $(c_i - 1)$ edges connecting the $j$-th and the $(j + 1)$-th vertices for each $1 \le j < c_i$.

Now you decided to unite chains in one graph in the following way:

the first chain is skipped;

the $1$-st vertex of the $i$-th chain is connected by an edge with the $a_i$-th vertex of the $(i - 1)$-th chain;

the last ($c_i$-th) vertex of the $i$-th chain is connected by an edge with the $b_i$-th vertex of the $(i - 1)$-th chain.

Picture of the first test case. Dotted lines are the edges added during uniting process

Calculate the length of the longest simple cycle in the resulting graph.

A simple cycle is a chain where the first and last vertices are connected as well. If you travel along the simple cycle, each vertex of this cycle will be visited exactly once.


-----Input-----

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

The first line of each test case contains the single integer $n$ ($2 \le n \le 10^5$) — the number of chains you have.

The second line of each test case contains $n$ integers $c_1, c_2, \dots, c_n$ ($2 \le c_i \le 10^9$) — the number of vertices in the corresponding chains.

The third line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($a_1 = -1$; $1 \le a_i \le c_{i - 1}$).

The fourth line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ($b_1 = -1$; $1 \le b_i \le c_{i - 1}$).

Both $a_1$ and $b_1$ are equal to $-1$, they aren't used in graph building and given just for index consistency. It's guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$.


-----Output-----

For each test case, print the length of the longest simple cycle.


-----Examples-----

Input
3
4
3 4 3 3
-1 1 2 2
-1 2 2 3
2
5 6
-1 5
-1 1
3
3 5 2
-1 1 1
-1 3 5
Output
7
11
8


-----Note-----

In the first test case, the longest simple cycle is shown below:

We can't increase it with the first chain, since in such case it won't be simple — the vertex $2$ on the second chain will break simplicity.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Graph algorithms

Greedy algorithms


Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	len = [0 for i in range(n)]
	for i in range(1, n):
		d = abs(b[i] - a[i])
		len[i] = c[i] + 1 + int(d != 0) * max(d, len[i - 1] - d)
	print(max(len))


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
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())

class SMT:

	def __init__(self, arr):
		self.n = len(arr) - 1
		self.arr = [0] * (self.n << 2)
		self.lazy = [0] * (self.n << 2)

		def Build(l, r, rt):
			if l == r:
				self.arr[rt] = arr[l]
				return
			m = l + r >> 1
			Build(l, m, rt << 1)
			Build(m + 1, r, rt << 1 | 1)
			self.pushup(rt)
		Build(1, self.n, 1)

	def pushup(self, rt):
		self.arr[rt] = self.arr[rt << 1] + self.arr[rt << 1 | 1]

	def pushdown(self, rt, ln, rn):
		if self.lazy[rt]:
			self.lazy[rt << 1] += self.lazy[rt]
			self.lazy[rt << 1 | 1] += self.lazy[rt]
			self.arr[rt << 1] += self.lazy[rt] * ln
			self.arr[rt << 1 | 1] += self.lazy[rt] * rn
			self.lazy[rt] = 0

	def update(self, L, R, c, l=1, r=None, rt=1):
		if r == None:
			r = self.n
		if L <= l and r <= R:
			self.arr[rt] += c * (r - l + 1)
			self.lazy[rt] += c
			return
		m = l + r >> 1
		self.pushdown(rt, m - l + 1, r - m)
		if L <= m:
			self.update(L, R, c, l, m, rt << 1)
		if R > m:
			self.update(L, R, c, m + 1, r, rt << 1 | 1)
		self.pushup(rt)

	def query(self, L, R, l=1, r=None, rt=1):
		if r == None:
			r = self.n
		if L <= l and R >= r:
			return self.arr[rt]
		m = l + r >> 1
		self.pushdown(rt, m - l + 1, r - m)
		ans = 0
		if L <= m:
			ans += self.query(L, R, l, m, rt << 1)
		if R > m:
			ans += self.query(L, R, m + 1, r, rt << 1 | 1)
		return ans

class SMT:

	def __init__(self, arr):
		self.n = len(arr) - 1
		l = n.bit_length()
		self.arr = [0] * (1 << l + 1)
		self.lazy = [-1] * (1 << l + 1)

		def Build(l, r, rt):
			if l == r:
				self.arr[rt] = arr[l]
				return
			m = l + r >> 1
			Build(l, m, rt << 1)
			Build(m + 1, r, rt << 1 | 1)
			self.pushup(rt)
		Build(1, self.n, 1)

	def pushup(self, rt):
		self.arr[rt] = self.arr[rt << 1] + self.arr[rt << 1 | 1]

	def pushdown(self, rt, ln, rn):
		if self.lazy[rt] != -1:
			self.lazy[rt << 1] = self.lazy[rt]
			self.lazy[rt << 1 | 1] = self.lazy[rt]
			self.arr[rt << 1] = self.lazy[rt] * ln
			self.arr[rt << 1 | 1] = self.lazy[rt] * rn
			self.lazy[rt] = -1

	def update(self, L, R, c, l=1, r=None, rt=1):
		if r == None:
			r = self.n
		if L <= l and r <= R:
			self.arr[rt] = c * (r - l + 1)
			self.lazy[rt] = c
			return
		m = l + r >> 1
		self.pushdown(rt, m - l + 1, r - m)
		if L <= m:
			self.update(L, R, c, l, m, rt << 1)
		if R > m:
			self.update(L, R, c, m + 1, r, rt << 1 | 1)
		self.pushup(rt)

	def query(self, L, R, l=1, r=None, rt=1):
		if r == None:
			r = self.n
		if L <= l and R >= r:
			return self.arr[rt]
		m = l + r >> 1
		self.pushdown(rt, m - l + 1, r - m)
		ans = 0
		if L <= m:
			ans += self.query(L, R, l, m, rt << 1)
		if R > m:
			ans += self.query(L, R, m + 1, r, rt << 1 | 1)
		return ans
t = N()
for i in range(t):
	n = N()
	c = RLL()
	a = RLL()
	b = RLL()
	dp = [0] * n
	ans = 0
	for i in range(1, n):
		if a[i] == b[i]:
			dp[i] = 1 + c[i]
		else:
			dp[i] = max(c[i] + abs(a[i] - b[i]) + 1, c[i] + dp[i - 1] - (abs(a[i] - b[i]) - 1))
		ans = max(ans, dp[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	lis = []
	lis.append(0)
	lis.append(1 + c[1] + abs(b[1] - a[1]))
	for i in range(n - 2):
		if a[i + 2] != b[i + 2]:
			aa = abs(a[i + 2] - b[i + 2]) + c[i + 2] + 1
			ab = c[i + 2] + lis[i + 1] - abs(a[i + 2] - b[i + 2]) + 1
			lis.append(max(aa, ab))
		else:
			aa = abs(a[i + 2] - b[i + 2]) + c[i + 2] + 1
			lis.append(aa)
	print(max(lis))


for t in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	curlen = 0
	lstcur = 0
	ans = 0
	for i in range(1, n):
		curlen = abs(a[i] - b[i]) + 1 + c[i]
		if a[i] != b[i]:
			curlen = max(curlen, c[i] + 1 + lstcur - abs(a[i] - b[i]))
			lstcur = curlen
		ans = max(ans, curlen)
		lstcur = curlen
	print(ans)


from math import ceil
t = int(input())
for z in range(t):
	n = int(input())
	c = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	ma = 0
	sum = abs(a[1] - b[1]) + 2
	for i in range(1, n):
		ma = max(ma, sum + c[i] - 1)
		if i == n - 1:
			break
		abd = abs(a[i + 1] - b[i + 1])
		toabd = c[i] - abd - 1
		if abd == 0:
			sum = 2
			continue
		sum = max(sum + toabd + 2, abd + 2)
	print(ma)


t = int(input())
for _ in range(t):
	n = int(input())
	crr = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] > brr[i]:
			(arr[i], brr[i]) = (brr[i], arr[i])
	ans = 0
	maxi = 0
	for i in range(1, n):
		if i == 1:
			maxi = brr[i] - arr[i] + 2
		else:
			maxi = max(maxi + arr[i] - 1 + crr[i - 1] - brr[i] + 2, brr[i] - arr[i] + 2)
		if brr[i] - arr[i] == 0:
			maxi = 2
		ans = max(ans, maxi + crr[i] - 1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = max(c[1:]) + 1
	C = 2 + c[-1] - 1
	for i in range(n - 1, 1, -1):
		if a[i] == b[i]:
			if ans < C:
				ans = C
			C = 2
			C += a[i] - 1 + (c[i - 1] - a[i])
		else:
			if ans < C + abs(a[i] - b[i]):
				ans = C + abs(a[i] - b[i])
			C += min(a[i], b[i]) - 1 + (c[i - 1] - max(a[i], b[i]))
			C = max(C, c[i - 1] - 1)
			C += 2
	C += abs(a[1] - b[1])
	if C > ans:
		ans = C
	print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, C, A, B):
	best = 0
	curr = 0
	for i in range(1, N):
		(a, b, c) = (A[i], B[i], C[i])
		assert a >= 1
		assert b >= 1
		assert c >= 2
		if i == 1:
			curr = abs(b - a)
		elif a == b:
			curr = 0
		else:
			curr = max(abs(b - a), curr - abs(b - a))
		curr += 2 + c - 1
		best = max(best, curr)
	return best
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()]
	C = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = solve(N, C, A, B)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	c = l[n - 1]
	for i in range(n - 1, 0, -1):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
		if i == 1:
			c += b[i] - a[i] + 1
			ans = max(ans, c, c - b[i] + a[i] - 1 + b[i] - a[i] + 1)
		elif a[i] == b[i]:
			c += 1
			ans = max(ans, c)
		else:
			c += a[i] + l[i - 1] - b[i] + 1
			ans = max(ans, c, c - a[i] - l[i - 1] + b[i] - 1 + b[i] - a[i] + 1)
		if a[i] == b[i]:
			c = l[i - 1]
		else:
			c = max(l[i - 1], c)
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	cc = [int(x) for x in input().split()]
	aa = [int(x) for x in input().split()]
	bb = [int(x) for x in input().split()]
	state = 'OPEN'
	cur_size = 0
	max_size = 0
	for i in range(n - 1):
		c = cc[i]
		a = aa[i + 1]
		b = bb[i + 1]
		if state == 'OPEN':
			cur_size += abs(a - b) + 2
			state = 'CONTINUE'
		elif state == 'CONTINUE':
			force_end_size = cur_size + c - 1
			if force_end_size > max_size:
				max_size = force_end_size
			cur_size += c - abs(a - b) - 1
			if a == b:
				if max_size < cur_size:
					max_size = cur_size
				cur_size = 2
			else:
				if cur_size < abs(a - b):
					cur_size = abs(a - b)
				cur_size += 2
	cur_size += cc[-1] - 1
	if max_size < cur_size:
		max_size = cur_size
	print(max_size)


k = int(input())
while k:
	k -= 1
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ans, t) = (0, 0)
	for i in range(1, n):
		x = abs(a[i] - b[i])
		if x == 0:
			t = c[i] + 1
		else:
			t = max(x, t - x) + c[i] + 1
		ans = max(ans, t)
	print(ans)


from bisect import bisect_left
for _ in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	dp = [-1, 2 + abs(a[1] - b[1]) + c[1] - 1]
	for i in range(2, n):
		if a[i] == b[i]:
			dp.append(2 + c[i] - 1)
		else:
			dp.append(max(dp[-1] + 2 + c[i] + min(a[i], b[i]) - 1 - max(a[i], b[i]), c[i] + 1 + abs(a[i] - b[i])))
	print(max(dp))


import math
from collections import defaultdict
DEBUG = False

def log(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)

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

def readlist(f):
	return list(map(f, input().split()))

class Solution:

	def __init__(self):
		pass

	def run(self):
		n = readint()
		c = readlist(int)
		a = readlist(int)
		b = readlist(int)
		current = 0
		result = 0
		for i in range(1, n):
			log('before', i, current, c[i], a[i], b[i])
			if a[i] == b[i]:
				log('same, reset')
				current = 2
			else:
				diff = abs(a[i] - b[i])
				log('gap', diff, current + c[i - 1] - 1 - diff)
				current = max(diff, current - diff) + 2
			current += c[i] - 1
			log('after', i, current)
			result = max(result, current)
		return result
t = int(input())
s = Solution()
for i in range(t):
	print(s.run())


def main():
	for _ in range(int(input())):
		n = int(input())
		c = list(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		(ans, t) = (0, 0)
		for i in range(1, n):
			x = abs(a[i] - b[i])
			t = c[i] + 1 if x == 0 else max(x, t - x) + c[i] + 1
			ans = max(ans, t)
		print(ans)
main()


for tt in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	cnt = 0
	cnt = c[n - 1] - 1
	for i in range(n - 2, -1, -1):
		if a[i + 1] != b[i + 1]:
			cnt += 2
			ans = max(ans, cnt + abs(a[i + 1] - b[i + 1]))
			if a[i + 1] < b[i + 1]:
				cnt += a[i + 1] - 1 + c[i] - b[i + 1]
			else:
				cnt += c[i] - a[i + 1] + b[i + 1] - 1
			cnt = max(cnt, c[i] - 1)
		else:
			ans = max(cnt + 2, ans)
			cnt = c[i] - 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()] + [1]
	b = [int(i) for i in input().split()] + [1]
	current = abs(a[1] - b[1])
	best = 0
	for i in range(1, n):
		current += 2 + c[i] - 1 - abs(a[i + 1] - b[i + 1])
		best = max(best, current + abs(a[i + 1] - b[i + 1]))
		current = max(current, abs(a[i + 1] - b[i + 1]))
		if a[i + 1] == b[i + 1]:
			current = 0
	print(best)


from math import ceil

def solve(n, a, b, c):
	ans = 0
	cur = 0
	for i in range(1, n):
		if a[i] == b[i]:
			cur = c[i] + 1
		else:
			temp = abs(a[i] - b[i]) + 1 + c[i]
			cur -= abs(a[i] - b[i]) - 1
			cur += c[i]
			cur = max(cur, temp)
		ans = max(ans, cur)
	return ans
T = int(input())
for t in range(T):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = solve(n, a, b, c)
	print(ans)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

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

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	N = inputnum()
	C = inputlist()
	A = inputlist()
	B = inputlist()
	best = 0
	l = C[-1]
	for i in range(N - 1, 0, -1):
		(a, b) = (A[i], B[i])
		if a > b:
			(a, b) = (b, a)
		best = max(best, l + (b - a + 1))
		c = C[i - 1]
		if a != b:
			l = max(l + (c - b + 1) + a, c)
		else:
			l = c
	print(best)


for t in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	s = 0
	for i in range(1, n):
		x = c[i] + abs(b[i] - a[i]) + 1
		if a[i] != b[i] and i != 1:
			s += c[i] - abs(b[i] - a[i]) + 1
		if a[i] == b[i]:
			s = 1
		s = max(x, s)
		if s > ans:
			ans = s
	print(ans)


import sys
input = sys.stdin.readline

def solution(n, c, a, b):
	intervals = [[min(ai, bi), max(ai, bi)] for (ai, bi) in zip(a, b)]
	branches = [0 for _ in range(n)]
	sol = 0
	for i in range(1, n):
		if intervals[i][1] == intervals[i][0]:
			branches[i] = 1
		elif i == 1:
			branches[i] = intervals[i][1] - intervals[i][0] + 1
		else:
			val1 = intervals[i][1] - intervals[i][0] + 1
			val2 = intervals[i][0] + c[i - 1] - intervals[i][1] + 1 + branches[i - 1]
			branches[i] = max(val1, val2)
	sol = max((branches[i] + c[i] for i in range(1, n)))
	print(sol)
T = int(input())
for t in range(T):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solution(n, c, a, b)


for _ in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	lengths = [0]
	for ind in range(1, n):
		if a[ind] == b[ind]:
			lengths.append(c[ind] + 1)
		else:
			lengths.append(c[ind] + 1 + max(lengths[-1] - abs(a[ind] - b[ind]), abs(a[ind] - b[ind])))
	print(max(lengths))


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	c = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	ans = c[1] + abs(a[1] - b[1]) + 1
	cur = ans
	for i in range(2, n):
		if a[i] == b[i]:
			cur = c[i] + 1
		else:
			cur += c[i] - abs(a[i] - b[i]) + 1
			cur = max(cur, c[i] + abs(a[i] - b[i]) + 1)
		ans = max(ans, cur)
	print(ans)


def simple_cycle(n, a, b, c):
	maxi = 0
	if a[1] == b[1]:
		s = 1 + c[1]
		maxi = s
	else:
		s = abs(b[1] - a[1]) + 1 + c[1]
		maxi = s
	for i in range(2, n):
		if b[i] == a[i]:
			s = 1 + c[i]
		else:
			s = max(s - abs(b[i] - a[i]) + 1 + c[i], abs(b[i] - a[i]) + 1 + c[i])
		if maxi < s:
			maxi = s
	return maxi
t = int(input())
for i in range(0, t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(simple_cycle(n, a, b, c))


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	c = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	c[0] = 0
	s = 0
	m = 0
	z = 0
	for k in range(1, n):
		if b[k] < a[k]:
			(a[k], b[k]) = (b[k], a[k])
	for k in range(1, n):
		if a[k] != b[k]:
			m = max(m + a[k] + c[k - 1] + 1 - b[k], b[k] - a[k] + 1)
			s = max(c[k] + m, s)
		else:
			z = max(z, s)
			s = 1 + c[k]
			m = 1
	print(max(z, s))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	max_ans = 0
	ans = 0
	for i in range(1, n):
		(a[i], b[i]) = (min(a[i], b[i]), max(a[i], b[i]))
		if b[i] == a[i]:
			ans = 0
		ans = max(ans + 2 + (c[i] - 1) - (b[i] - a[i]), 2 + (c[i] - 1) + (b[i] - a[i]))
		max_ans = max(ans, max_ans)
	print(max_ans)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	ans = 0
	cur = 0
	for i in range(1, n):
		if a[i] == b[i]:
			cur = 0
		cur = max(c[i] + abs(a[i] - b[i]) + 1, cur + c[i] - abs(a[i] - b[i]) + 1)
		ans = max(ans, cur)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	lengthOfChains = [int(x) for x in input().split()]
	prevA = [int(x) for x in input().split()]
	prevB = [int(x) for x in input().split()]
	result = 0
	longestChainLength = 0
	answer = 0
	for i in range(1, n):
		diff = abs(prevA[i] - prevB[i])
		if diff == 0:
			longestChainLength = lengthOfChains[i] - 1 + diff + 2
		else:
			longestChainLength = lengthOfChains[i] - 1 + 2 + max(diff, longestChainLength - diff)
		answer = max(answer, longestChainLength)
	print(answer)


import sys, io, os
if os.environ['USERNAME'] == 'kissz':
	inp = open('in.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())
	(_, *C) = map(int, inp().split())
	(_, *A) = map(int, inp().split())
	(_, *B) = map(int, inp().split())
	best = 0
	L = 0
	for (c, a, b) in zip(C, A, B):
		if a == b:
			L = c + 1
		else:
			L = c + 1 + max(abs(a - b), L - abs(a - b))
		debug(c, a, b, L)
		best = max(best, L)
	print(best)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	maxi = 0
	prev = 0
	for i in range(1, n):
		if a[i] == b[i]:
			prev = abs(b[i] - a[i]) + 2 + arr[i] - 1
		elif i == 1:
			prev = 2 + abs(b[i] - a[i]) + arr[i] - 1
		else:
			a1 = prev + 2 - abs(b[i] - a[i]) + arr[i] - 1
			a2 = abs(b[i] - a[i]) + 2 + arr[i] - 1
			prev = max(a1, a2)
		maxi = max(maxi, prev)
	print(maxi)


for y in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxx = lst[-1]
	cur = lst[-1]
	for i in range(n):
		if b[i] < a[i]:
			(a[i], b[i]) = (b[i], a[i])
	for i in range(n - 1, 0, -1):
		if a[i] == b[i]:
			maxx = max(cur + 1, maxx)
			cur = lst[i - 1]
		else:
			maxx = max(maxx, cur + b[i] - a[i] + 1)
			cur = max(cur + a[i] + lst[i - 1] - b[i] + 1, lst[i - 1])
	print(maxx)


from sys import stdin, stdout
input = stdin.readline

def output(answer):
	stdout.write(str(answer) + '\n')
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	curr = None
	mx = 0
	for index in range(1, n):
		if a[index] == b[index]:
			curr = 2
		elif curr == None:
			dist = abs(a[index] - b[index])
			curr = dist + 2
		else:
			dist1 = abs(max(a[index], b[index]) - c[index - 1])
			dist2 = abs(min(a[index], b[index]) - 1)
			spc = abs(a[index] - b[index]) + 2
			dist = dist1 + dist2
			curr += dist + 2
			curr = max(curr, spc)
		mx = max(mx, curr + c[index] - 1)
	output(mx)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	C = list(map(int, input().split()))[::-1]
	A = list(map(int, input().split()))[::-1]
	B = list(map(int, input().split()))[::-1]
	DP = [0] * n
	DP[0] = C[0] + 1
	for i in range(1, n - 1):
		x = abs(A[i - 1] - B[i - 1])
		if not x:
			DP[i] = C[i] + 1
		else:
			DP[i] = max(DP[i - 1] + C[i] + 1 - x, C[i] + 1)
	for i in range(n - 1):
		DP[i] += abs(A[i] - B[i])
	ans = max(DP)
	print(ans)


def solution():
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	currentLen = 0
	maxLen = 0
	for i in range(n):
		if i == 0:
			currentLen += abs(max(a[i + 1], b[i + 1]) - min(a[i + 1], b[i + 1]))
		if i > 0 and i < n - 1:
			currentLen += 2
			if a[i + 1] == b[i + 1]:
				currentLen += c[i] - 1
				maxLen = max(currentLen, maxLen)
				currentLen = 0
			else:
				currentLen1 = currentLen + (c[i] - 1)
				currentLen2 = max(a[i + 1], b[i + 1]) - min(a[i + 1], b[i + 1])
				currentLen = currentLen + min(a[i + 1], b[i + 1]) - 1 + c[i] - max(a[i + 1], b[i + 1])
				currentLen = max(currentLen, currentLen2)
				maxLen = max(currentLen1, maxLen)
		if i == n - 1:
			currentLen += 2
			currentLen += c[i] - 1
			maxLen = max(currentLen, maxLen)
	print(maxLen)
T = int(input())
while T:
	solution()
	T -= 1


for iter in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	origin = A[1] - 1 + abs(B[1] - C[1]) + 2
	mx = origin
	cur = origin
	for i in range(2, n):
		if B[i] != C[i]:
			new1 = A[i] + 1 + abs(B[i] - C[i])
			new2 = A[i] + 1 + cur - abs(B[i] - C[i])
			cur = max(new1, new2)
			mx = max(mx, new1, new2)
		else:
			cur = A[i] + 1
			mx = max(mx, cur)
	print(mx)


try:
	import sys
	t = int(input())
	while t != 0:
		n = int(input())
		lstc = list(map(int, input().split()))
		lsta = list(map(int, input().split()))
		lstb = list(map(int, input().split()))
		ans = sum_ = 0
		for i in range(1, n):
			x = lstc[i] + abs(lstb[i] - lsta[i]) + 1
			if lsta[i] != lstb[i] and i != 1:
				sum_ += lstc[i] - abs(lstb[i] - lsta[i]) + 1
			if lsta[i] == lstb[i]:
				sum_ = 1
			sum_ = max(sum_, x)
			if sum_ > ans:
				ans = sum_
		print(ans)
		t -= 1
except EOFError:
	print(' ')


import sys
inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def check_seq(cnt, lengths, edges1, edges2):
	f_i = []
	res = 0
	for i in range(1, cnt):
		v1 = min(edges1[i], edges2[i])
		v2 = max(edges1[i], edges2[i])
		if not f_i:
			f_i.append(v2 - v1 + 1)
			continue
		if v1 == v2:
			f_i.append(1)
			continue
		f_i.append(max(v2 - v1 + 1, v1 + lengths[i - 1] + -v2 + 1 + f_i[-1]))
	for j in range(cnt - 1):
		res = max(res, lengths[j + 1] + f_i[j])
	return res

def main():
	samples = read_one_int()
	res = ''
	for _ in range(samples):
		chains_cnt = read_one_int()
		chains_l = read_list_of_ints()
		edges1 = read_list_of_ints()
		edges2 = read_list_of_ints()
		res = check_seq(chains_cnt, chains_l, edges1, edges2)
		print(res)
main()


import math
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mx = max(a[1], b[1])
	mn = min(a[1], b[1])
	op = c[1] + mx - mn + 1
	cnt = mx - mn + 1
	for i in range(2, n):
		mx = max(a[i], b[i])
		mn = min(a[i], b[i])
		if b[i] != a[i]:
			cnt += mn + (c[i - 1] - mx + 1)
		else:
			cnt = 1
		if cnt < mx - mn + 1:
			cnt = mx - mn + 1
		op = max(op, c[i] + cnt)
	print(op)


for t in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = []
	for i in range(1, len(b)):
		if i == 1:
			ans.append(2 + abs(b[i] - a[i]) + (c[i] - 1))
		elif b[i] == a[i]:
			ans.append(2 + c[i] - 1)
		else:
			ans.append(max(2 + c[i] - 1 + ans[-1] - abs(b[i] - a[i]), 2 + abs(b[i] - a[i]) + (c[i] - 1)))
	print(max(ans))


from sys import stdin
from collections import Counter
from math import pow, sqrt, factorial, log10, log
from itertools import permutations, combinations, combinations_with_replacement
input = stdin.readline

def solve(n, a, b, c):
	re = 0
	first = 0
	for i in range(1, n):
		x = abs(a[i] - b[i])
		if x == 0:
			first = c[i] + 1
		else:
			first = max(x, first - x) + c[i] + 1
		re = max(re, first)
	print(re)
t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, a, b, c)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp = 0
	maxa = 0
	for i in range(1, n):
		if i == 1:
			temp += abs(b[i] - a[i]) + 2
		elif a[i] == b[i]:
			temp += c[i - 1] - 1
			if temp > maxa:
				maxa = temp
			temp = 2
		else:
			if temp + c[i - 1] - 1 > maxa:
				maxa = temp + c[i - 1] - 1
			if b[i] > a[i]:
				temp += a[i] - 1 + c[i - 1] - b[i] + 2
			else:
				temp += b[i] - 1 + c[i - 1] - a[i] + 2
			if temp < abs(b[i] - a[i]) + 2:
				temp = abs(b[i] - a[i]) + 2
		if i == n - 1:
			temp += c[i] - 1
			if temp > maxa:
				maxa = temp
	print(maxa)


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	curr = abs(a[1] - b[1])
	ans = curr
	for i in range(1, n - 1):
		ans = max(ans, curr + 1 + c[i])
		curr += c[i] + 1 - abs(a[i + 1] - b[i + 1])
		if a[i + 1] == b[i + 1]:
			ans = max(ans, curr)
			curr = 0
		elif abs(a[i + 1] - b[i + 1]) > curr:
			curr = abs(a[i + 1] - b[i + 1])
	curr += 1 + c[-1]
	ans = max(curr, ans)
	print(ans)


def length_cycle(n, a, b, c):
	longest_len = 0
	portion_of_prev_cycle_len = 0
	for i in range(1, n):
		curr_chain_length = c[i] - 1
		upper_node = min(a[i], b[i])
		lower_node = max(a[i], b[i])
		portion_of_prev_chain_len = lower_node - upper_node
		cycle_formed = curr_chain_length + portion_of_prev_chain_len + 2
		if a[i] != b[i]:
			cycle_formed_with_prev_part = portion_of_prev_cycle_len - portion_of_prev_chain_len + curr_chain_length + 2
			cycle_formed = max(cycle_formed, cycle_formed_with_prev_part)
		portion_of_prev_cycle_len = cycle_formed
		longest_len = max(longest_len, cycle_formed)
	return longest_len
t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(length_cycle(n, a, b, c))


from math import ceil

def solve(n, c, a, b):
	t = 0
	r = c[-1]
	for i in range(n - 1, 0, -1):
		if c[i] > r:
			r = c[i]
		if a[i] == b[i]:
			r += 1
			if r > t:
				t = r
			r = c[i - 1]
		else:
			if r + abs(a[i] - b[i]) + 1 > t:
				t = r + abs(a[i] - b[i]) + 1
			r += c[i - 1] - abs(a[i] - b[i]) + 1
	print(t)
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, c, a, b)


import sys
input = sys.stdin.buffer.readline
ans = []
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 0
	tmp = c[-1] - 1
	(pos_x, pos_y) = (1, c[-1])
	for i in range(n - 1, 0, -1):
		tmp += 2
		(pos_x, pos_y) = (min(a[i], b[i]), max(a[i], b[i]))
		res = max(res, tmp + pos_y - pos_x)
		if pos_x == pos_y:
			tmp = c[i - 1] - 1
			(pos_x, pos_y) = (1, c[i - 1])
		else:
			tmp += pos_x - 1 + c[i - 1] - pos_y
			if c[i - 1] - 1 >= tmp:
				tmp = c[i - 1] - 1
				(pos_x, pos_y) = (1, c[i - 1])
	ans.append(res)
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.append(c[-1] // 2)
	b.append(c[-1] // 2)
	maxx = 0
	curr2 = 0
	for i in range(1, n):
		curr = c[i] + 1 + abs(a[i] - b[i])
		if a[i] != b[i]:
			curr = max(curr, c[i] + 1 + curr2 - abs(a[i] - b[i]))
		maxx = max(maxx, curr)
		curr2 = curr
	print(maxx)


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lst = [0]
	for i in range(1, n):
		if a[i] == b[i]:
			lst += [c[i] + 1]
		else:
			lst += [c[i] + 1 + max(abs(a[i] - b[i]), lst[-1] - abs(a[i] - b[i]))]
	print(max(lst))


from math import ceil
from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	su = c[-1] - 1 + 2
	mx = su
	if a[-1] != b[-1]:
		mx = su + 1
	for i in range(n - 2, -1, -1):
		mx = max(mx, su)
		if a[i + 1] != b[i + 1]:
			mx = max(mx, su + abs(b[i + 1] - a[i + 1]))
		if c[i] - abs(b[i + 1] - a[i + 1]) + su > c[i] and a[i + 1] != b[i + 1]:
			su = c[i] - 1 - abs(b[i + 1] - a[i + 1]) + su + 2
		else:
			su = c[i] - 1 + 2
	print(mx)
	t -= 1


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	lengths = [0]
	for ind in range(1, n):
		if a[ind] == b[ind]:
			lengths.append(c[ind] + 1)
		else:
			lengths.append(c[ind] + 1 + max(lengths[-1] - abs(a[ind] - b[ind]), abs(a[ind] - b[ind])))
	print(max(lengths))


import collections, sys, functools, heapq, bisect, collections, math
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	n = int(input().strip())
	c = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	ans = 0
	curr = abs(b[1] - a[1])
	for i in range(1, n - 1):
		curr += 1 + c[i]
		ans = max(ans, curr)
		if b[i + 1] != a[i + 1]:
			curr -= abs(b[i + 1] - a[i + 1])
			curr = max(curr, abs(b[i + 1] - a[i + 1]))
		else:
			curr = 0
	curr += 1 + c[n - 1]
	ans = max(ans, curr)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	x = 0
	for i in range(1, n):
		if a[i] != b[i]:
			y = c[i] + 1
			if x == 0:
				x += y + abs(a[i] - b[i])
			else:
				x += y - abs(a[i] - b[i])
				z = c[i] + 1 + abs(a[i] - b[i])
				x = max(x, z)
		else:
			x = c[i] + 1
		if x > ans:
			ans = x
	print(ans)


import sys
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

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

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

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

def print_iterable(p):
	print(' '.join(map(str, p)))

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def main():
	t = get_int()
	for i in range(t):
		n = get_int()
		c = list_in()
		a = list_in()
		b = list_in()
		len = [0 for i in range(n)]
		for i in range(1, n):
			d = abs(b[i] - a[i])
			len[i] = c[i] + 1 + int(d != 0) * max(d, len[i - 1] - d)
		print(max(len))
	pass
main()


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [0] * n
	dp[0] = abs(b[1] - a[1])
	ans = 0
	for i in range(1, n):
		if i < n - 1:
			ai = a[i + 1]
			bi = b[i + 1]
		ans = max(ans, dp[i - 1] + 1 + c[i])
		if i == n - 1:
			break
		dp[i] = abs(bi - ai)
		if ai != bi:
			dp[i] = max(dp[i], dp[i - 1] + 2 + min(ai, bi) - 1 + c[i] - max(ai, bi))
	print(ans)


number_of_testcases = int(input())
for _ in range(number_of_testcases):
	chain_length = int(input())
	q = [0] * chain_length
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(chain_length):
		if i > 0:
			q[i] = max(c[i] + 1 + abs(a[i] - b[i]), c[i] + 1 + q[i - 1] - abs(a[i] - b[i]) if a[i] != b[i] else 0)
	print(max(q))


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxi = 0
	cnt = c[n - 1]
	for i in range(n - 1, 0, -1):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
		if a[i] == b[i]:
			cnt += 1
			maxi = max(maxi, cnt)
			cnt = c[i - 1]
		elif i == 1:
			cnt += b[i] - a[i] + 1
			maxi = max(maxi, cnt)
		else:
			cnt1 = cnt
			cnt1 += b[i] - a[i] + 1
			cnt += a[i] + (c[i - 1] - b[i] + 1)
			maxi = max(maxi, cnt)
			maxi = max(maxi, cnt1)
			if cnt < c[i - 1]:
				cnt = c[i - 1]
	print(maxi)


from sys import stdin
t = int(input())
for _ in range(t):
	n = int(stdin.readline())
	c = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	x = 0
	ans = 0
	t = 0
	for i in range(1, n):
		x = abs(a[i] - b[i])
		t = c[i] + 1 if x == 0 else max(x, t - x) + c[i] - 1 + 2
		ans = max(ans, t)
	print(ans)


t = int(input())
for i in range(t):
	(n,) = map(int, input().strip().split(' '))
	q = list(map(int, input().strip().split(' ')))
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	ans = 0
	pre_ans = 0
	for i in range(1, len(q)):
		cyc1 = abs(a[i] - b[i]) + 1 + q[i]
		if a[i] != b[i] and i != 1:
			cyc2 = pre_ans - abs(a[i] - b[i]) + 1 + q[i]
		else:
			cyc2 = 0
		pre_ans = max(cyc1, cyc2)
		ans = max(ans, pre_ans)
	print(ans)


def solve():
	n = int(input())
	c = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	current = 0
	best = 0
	for i in range(1, n):
		if a[i] == b[i]:
			current = 1 + c[i]
		else:
			diff = abs(a[i] - b[i])
			current = max(diff, current - diff) + 1 + c[i]
		best = max(current, best)
	print(best)
t = int(input())
for test in range(t):
	solve()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	C = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	dp = [0] * n
	dp[-1] = C[-1]
	ans = 0
	for i in range(n - 2, -1, -1):
		ans = max(ans, abs(A[i + 1] - B[i + 1]) + 1 + dp[i + 1])
		(a, b) = (min(A[i + 1], B[i + 1]), max(A[i + 1], B[i + 1]))
		dp[i] = max(C[i], dp[i])
		if a != b:
			dp[i] = max(dp[i], a + C[i] - b + 1 + dp[i + 1])
	return ans
for _ in range(int(input())):
	print(solve())


def sol(c, a, b):
	ans = abs(a[1] - b[1])
	ans_ = []
	ans_1 = [abs(a[1] - b[1])]
	for i in range(1, len(c)):
		if i < n - 1 and a[i + 1] != b[i + 1]:
			ans_1.append(ans + 2 + c[i] - 1)
			ans = max(ans + 2 + c[i] - 1 - abs(a[i + 1] - b[i + 1]), abs(a[i + 1] - b[i + 1]))
		elif i < n - 1:
			ans_.append(ans + 2 + c[i] - 1)
			ans_1.append(ans + 2 + c[i] - 1)
			ans = 0
		else:
			ans += c[n - 1] + 1
	m = 0
	if len(ans_) > 0:
		m = max(ans_)
	return max(ans, m, max(ans_1))
for _ in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	k = sol(c, a, b)
	print(k)


for _ in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	cnt = [0] * n
	curr = 0
	for i in range(1, n):
		if a[i] == b[i]:
			curr = 2
			ans = max(ans, curr + c[i] - 1)
		elif curr == 0:
			curr += abs(a[i] - b[i]) + 2
			ans = max(ans, curr + c[i] - 1)
		else:
			curr += min(a[i], b[i]) - 1 + c[i - 1] - max(a[i], b[i]) + 2
			curr = max(curr, abs(a[i] - b[i]) + 2)
			ans = max(ans, curr + c[i] - 1)
	ans = max(ans, curr + c[-1] - 1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	C = [int(t) for t in input().split()]
	A = [int(t) for t in input().split()]
	B = [int(t) for t in input().split()]
	ans = 0
	cur = 0
	for i in range(1, n):
		if A[i] != B[i]:
			cur = max(1 + C[i] + abs(A[i] - B[i]), cur + 1 + C[i] - abs(A[i] - B[i]))
		else:
			cur = 1 + C[i]
		ans = max(ans, cur)
	print(ans)


import sys
MOD = 10 ** 9 + 7
INF = float('inf')
T = int(input())
Ns = []
Cs = []
As = []
Bs = []
for _ in range(T):
	N = int(input())
	C = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Ns.append(N)
	Cs.append(C)
	As.append(A)
	Bs.append(B)
for i in range(T):
	N = Ns[i]
	C = Cs[i]
	A = As[i]
	B = Bs[i]
	res = 0
	t = abs(A[1] - B[1])
	for j in range(1, N):
		tend = t + 2 + C[j] - 1
		res = max(res, tend)
		if j < N - 1:
			M = max(A[j + 1], B[j + 1])
			m = min(A[j + 1], B[j + 1])
			if M == m:
				t = 0
			else:
				t = max(t + 2 + C[j] - M + m - 1, M - m)
	print('{}'.format(res))


def find(chains, first, last, n, ans):
	max_wt = 0
	add = chains[-1] - 1
	for i in range(n - 2, -1, -1):
		(a, b, c) = (first[i + 1], last[i + 1], chains[i + 1])
		add += 2
		max_wt = max(max_wt, add + abs(a - b))
		if a == b:
			add = 0
		else:
			(a, b) = (min(a, b), max(a, b))
			add += a - 1 + chains[i] - b
		if chains[i] - 1 > add:
			add = chains[i] - 1
	return max_wt

def find2(chains, first, last, n, ans):
	max_wt = 0
	add = 0
	for i in range(1, n):
		(a, b, c) = (first[i], last[i], chains[i])
		if i == 1:
			add += abs(a - b)
		if a == b:
			add = 0
		else:
			(a, b) = (min(a, b), max(a, b))
			add += a - 1 + chains[i - 1] - b
			add += 2
		max_wt = max(max_wt, add + c - 1)
		if abs(a - b) > add:
			add = abs(a - b)
	return max_wt

def solve(chains, first, last, n, ans):
	max_wt = find(chains, first, last, n, ans)
	ans.append(str(max_wt))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		chains = list(map(int, input().split()))
		first = list(map(int, input().split()))
		last = list(map(int, input().split()))
		solve(chains, first, last, n, ans)
	print('\n'.join(ans))
main()


T = int(input())
r = 1

def getnext(index, diff, chain, dp, ans):
	if dp[index] >= 0:
		return dp[index]
	if diff[index] > 0:
		num1 = chain[index] - diff[index] + 1 + getnext(index + 1, diff, chain, dp, ans)
		num2 = chain[index]
		dp[index] = max(num1, num2)
	else:
		dp[index] = chain[index]
	newnum = diff[index] + 1 + getnext(index + 1, diff, chain, dp, ans)
	ans[0] = max(ans[0], newnum)
	return dp[index]
while r <= T:
	n = int(input())
	chain = list(map(int, input().split()))
	front = list(map(int, input().split()))
	rear = list(map(int, input().split()))
	diff = []
	for i in range(1, n):
		diff.append(abs(front[i] - rear[i]))
	dp = [-1] * n
	dp[-1] = chain[-1]
	ans = 0
	for index in range(n - 2, -1, -1):
		if diff[index] > 0:
			num1 = chain[index] - diff[index] + 1 + getnext(index + 1, diff, chain, dp, ans)
			num2 = chain[index]
			dp[index] = max(num1, num2)
		else:
			dp[index] = chain[index]
		newnum = diff[index] + 1 + dp[index + 1]
		ans = max(ans, newnum)
	print(ans)
	r += 1


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

def solve():
	n = int(input())
	chains = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = []
	for i in range(1, len(chains)):
		cycle = abs(b[i] - a[i]) + chains[i] + 1
		if i != 1 and b[i] != a[i]:
			dp.append(max(dp[i - 2] + cycle - abs(b[i] - a[i]) * 2, cycle))
		else:
			dp.append(cycle)
	print(max(dp))
main()


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	initialSpan = c[1] + abs(b[1] - a[1]) + 1
	maxSpan = initialSpan
	for i in range(2, n):
		if b[i] != a[i]:
			initialSpan += c[i]
			initialSpan -= abs(b[i] - a[i]) - 1
			secSpan = c[i] + abs(b[i] - a[i]) + 1
			if secSpan > initialSpan:
				maxSpan = max(maxSpan, initialSpan)
				maxSpan = max(maxSpan, secSpan)
				initialSpan = secSpan
		else:
			initialSpan = c[i] + 1
		maxSpan = max(maxSpan, initialSpan)
	maxSpan = max(maxSpan, initialSpan)
	print(maxSpan)


import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from heapq import heappush, heappop, heapify
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
sys.setrecursionlimit(100000000)
intinp = lambda : int(input().strip())
stripinp = lambda : input().strip()
fltarr = lambda : list(map(float, input().strip().split()))
intarr = lambda : list(map(int, input().strip().split()))
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
MOD = 1000000007
num_cases = intinp()
for _ in range(num_cases):
	n = intinp()
	carr = intarr()
	aarr = intarr()
	barr = intarr()
	ans = 0
	curr = 0
	for i in range(1, n):
		if i == 1:
			curr = carr[i] + abs(aarr[i] - barr[i]) + 1
		elif aarr[i] == barr[i]:
			curr = carr[i] + 1
		else:
			curr = max(curr + carr[i] - (abs(aarr[i] - barr[i]) - 1), carr[i] + abs(aarr[i] - barr[i]) + 1)
		ans = max(ans, curr)
	print(ans)


import sys
r = sys.stdin.readline
for _ in range(int(r())):
	N = int(r())
	C = list(map(int, r().split()))
	A = list(map(int, r().split()))
	B = list(map(int, r().split()))
	S = 0
	ans = 0
	for i in range(1, N):
		if i == 1:
			S = abs(A[i] - B[i]) + 2 + (C[i] - 1)
		elif A[i] == B[i]:
			S = 2 + (C[i] - 1)
		elif S < 2 * abs(A[i] - B[i]):
			S = abs(A[i] - B[i]) + 2 + (C[i] - 1)
		else:
			S += 2 - abs(A[i] - B[i]) + (C[i] - 1)
		if S > ans:
			ans = S
	print(ans)


import math
T = int(input())
for t in range(T):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	current_cycle = abs(a[1] - b[1]) + 1
	best_cycle_till_now = 0
	for i in range(1, n - 1):
		best_cycle_till_now = max(best_cycle_till_now, current_cycle + c[i])
		if a[i + 1] == b[i + 1]:
			current_cycle = 1
		else:
			current_cycle = max(abs(a[i + 1] - b[i + 1]) + 1, current_cycle + (c[i] - abs(a[i + 1] - b[i + 1])) + 1)
	best_cycle_till_now = max(best_cycle_till_now, current_cycle + c[n - 1])
	print(best_cycle_till_now)


from collections import *
from math import *
M = 10 ** 9 + 7
maxx = 10 ** 20

def abss(n):
	if n > 0:
		return n
	return -n
for i in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 0
	tmp = c[0] - 1
	for i in range(1, n):
		if a[i] == b[i]:
			tmp = 2 + c[i] - 1
		elif i - 1 != 0:
			tmp = max(tmp - (c[i - 1] - 1) + 2 + c[i] - 1 + (c[i - 1] - 1 - abss(b[i] - a[i])), abss(b[i] - a[i]) + 2 + c[i] - 1)
		else:
			tmp = abss(b[i] - a[i]) + 2 + c[i] - 1
		res = max(res, tmp)
	print(res)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		vert = list(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		(dp, ans) = (-10 ** 10, 0)
		for i in range(1, n):
			if a[i] == b[i]:
				dp = 0
			else:
				dp = max(dp + min(a[i], b[i]) - 1 + vert[i - 1] - max(b[i], a[i]) + 2, abs(b[i] - a[i]))
			ans = max(ans, dp + 1 + vert[i])
		print(ans)
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 t in range(T):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	dp = [0 for i in range(n)]
	for i in range(1, n):
		if a[i] == b[i]:
			dp[i] = c[i] + 1 + abs(a[i] - b[i])
		else:
			dp[i] = max(dp[i - 1] + c[i] + 1 - abs(a[i] - b[i]), c[i] + 1 + abs(a[i] - b[i]))
	print(max(dp))


t = int(input())
import math
while t > 0:
	t -= 1
	n = int(input())
	ci = [int(op) for op in input().split()]
	ai = [int(op) for op in input().split()]
	bi = [int(op) for op in input().split()]
	ans = 0
	m = 0
	lc = 0
	for i in range(n - 1):
		if ai[i + 1] == bi[i + 1]:
			ans = max(m + lc, ans)
			m = 2
		else:
			m = max(abs(ai[i + 1] - bi[i + 1]), m + lc - abs(ai[i + 1] - bi[i + 1])) + 2
		ans = max(m + ci[i + 1] - 1, ans)
		lc = ci[i + 1] - 1
	print(ans)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	final = 0
	temp = 0
	flag = 0
	for i in range(1, n):
		if a[i] != b[i]:
			if temp != 0:
				temp += min(a[i], b[i]) - 1 + c[i - 1] - max(a[i], b[i]) + 2
				temp = max(temp, abs(a[i] - b[i]) + 2)
				final = max(final, temp + c[i] - 1)
			else:
				temp += abs(a[i] - b[i]) + 2
				final = max(final, temp + c[i] - 1)
		else:
			temp = 2
			final = max(final, temp + c[i] - 1)
	final = max(final, temp + c[-1] - 1)
	print(final)


import sys
input = sys.stdin.readline
from itertools import accumulate
from math import ceil
for _ in range(int(input())):
	n = int(input())
	C = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	dp = [0] * n
	ans = 0
	for i in range(1, n):
		cur = C[i] - 1 + 2 + abs(A[i] - B[i])
		if A[i] != B[i]:
			cur2 = dp[i - 1] - abs(A[i] - B[i]) + C[i] - 1 + 2
			cur = max(cur, cur2)
		ans = max(ans, cur)
		dp[i] = cur
	print(ans)


from io import BytesIO, IOBase
import sys
import math
import os
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))

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

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

def mfloat():
	return map(float, input().split())

def solve():
	n = int(input())
	(*c,) = mint()
	(*a,) = mint()
	(*b,) = mint()
	if b[1] < a[1]:
		(a[1], b[1]) = (b[1], a[1])
	ans = c[1] + 2 + b[1] - a[1] - 1
	current_length = ans
	for i in range(2, n):
		if b[i] < a[i]:
			(a[i], b[i]) = (b[i], a[i])
		if b[i] != a[i]:
			current_length = max(current_length + 2 + c[i] - 1 - (b[i] - a[i]), b[i] - a[i] + 2 + c[i] - 1)
		else:
			current_length = 2 + c[i] - 1
		ans = max(ans, current_length)
	print(ans)

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


def cycle(n, vert, a, b):
	idx = len(a) - 1
	max_so_far = 0
	chain_len = int(vert[idx]) - 1
	while idx > 1:
		chain_len += 2
		max_so_far = max(max_so_far, chain_len + abs(int(a[idx]) - int(b[idx])))
		if int(a[idx]) == int(b[idx]):
			max_so_far = max(max_so_far, chain_len)
			chain_len = int(vert[idx - 1]) - 1
		else:
			chain_len += int(vert[idx - 1]) - 1 - abs(int(a[idx]) - int(b[idx]))
			if int(vert[idx - 1]) - 1 > chain_len:
				chain_len = int(vert[idx - 1]) - 1
		idx -= 1
	chain_len += 2
	chain_len += abs(int(a[idx]) - int(b[idx]))
	max_so_far = max(max_so_far, chain_len)
	return max_so_far
num_test_cases = int(input())
for i in range(num_test_cases):
	n = int(input())
	vert = input().split()
	a = input().split()
	b = input().split()
	print(cycle(n, vert, a, b))


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	b1 = 0
	for i in range(len(c) - 1):
		if i == 0:
			b1 = max(b1, abs(b[i + 1] - a[i + 1]))
		else:
			b1 += c[i] + 1
			ans = max(b1, ans)
			a1 = abs(b[i + 1] - a[i + 1])
			b1 -= a1
			b1 = max(b1, a1)
			if a1 == 0:
				b1 = 0
	b1 += c[-1] + 1
	ans = max(ans, b1)
	print(ans)


import math
YES = 'YES'
NO = 'NO'
MOD = 1000000007

def input_int():
	return int(input())

def input_list():
	return input().split(' ')

def input_list_int():
	return list(map(int, input_list()))

def solve():
	n = input_int()
	c = input_list_int()
	a = input_list_int()
	b = input_list_int()
	ans = 0
	last = 0
	for i in range(1, n):
		cur = c[i] + 1 + abs(a[i] - b[i])
		if a[i] != b[i]:
			cur = max(cur, c[i] + 1 + last - abs(a[i] - b[i]))
		ans = max(ans, cur)
		last = cur
	print(ans)
query_count = input_int()
while query_count:
	query_count -= 1
	solve()


t = int(input())
for z in range(t):
	n = int(input())
	l = input().split(' ')
	c = []
	for val in l:
		c.append(int(val))
	l = input().split(' ')
	a = []
	for val in l:
		a.append(int(val))
	l = input().split(' ')
	b = []
	for val in l:
		b.append(int(val))
	for i in range(n):
		if a[i] > b[i]:
			x = a[i]
			a[i] = b[i]
			b[i] = x
	dp = []
	for i in range(n):
		dp.append(0)
	dp[n - 1] = c[n - 1]
	best = 0
	l = []
	for i in range(n - 1):
		l.append(i)
	l.reverse()
	for i in l:
		dp[i] = c[i]
		if a[i + 1] != b[i + 1]:
			dp[i] = max(dp[i], dp[i + 1] + a[i + 1] + c[i] - b[i + 1] + 1)
		best = max(best, dp[i + 1] + b[i + 1] - a[i + 1] + 1)
	print(best)


import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	max_ans = 0
	ans = 0
	for i in range(1, n):
		(a[i], b[i]) = (min(a[i], b[i]), max(a[i], b[i]))
		if b[i] == a[i]:
			ans = 0
		ans = max(ans + 2 + (c[i] - 1) - (b[i] - a[i]), 2 + (c[i] - 1) + (b[i] - a[i]))
		max_ans = max(ans, max_ans)
	print(max_ans)


from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
for CASES in range(int(input())):
	n = int(input())
	C = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.append(1)
	B.append(1)
	i = 0
	tmp = 0
	ans = 0
	while True:
		tmp += abs(A[i + 1] - B[i + 1])
		tmp += 2
		i += 1
		while abs(A[i + 1] - B[i + 1]) != 0:
			ans = max(ans, tmp + C[i] - 1)
			tmp += C[i] - 1 - abs(A[i + 1] - B[i + 1])
			tmp = max(tmp, abs(A[i + 1] - B[i + 1]))
			tmp += 2
			i += 1
		tmp += C[i] - 1
		ans = max(ans, tmp)
		if i + 1 == len(A) - 1:
			break
		else:
			tmp = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	vert = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(dp, ans) = (-10 ** 10, 0)
	for i in range(1, n):
		if a[i] == b[i]:
			dp = 0
		else:
			dp = max(dp + min(a[i], b[i]) - 1 + vert[i - 1] - max(b[i], a[i]) + 2, abs(b[i] - a[i]))
		ans = max(ans, dp + 1 + vert[i])
	print(ans)


def longest(size, up, low):
	ans = abs(low[1] - up[1]) + 1 + size[1]
	curr = abs(up[1] - low[1])
	for i in range(1, len(size) - 1):
		ans = max(ans, curr + size[i] + 1)
		curr += size[i] + 1 - abs(up[i + 1] - low[i + 1])
		if up[i + 1] == low[i + 1]:
			ans = max(ans, curr)
			curr = 0
		elif abs(up[i + 1] - low[i + 1]) > curr:
			curr = abs(up[i + 1] - low[i + 1])
	curr += 1 + size[-1]
	return max(ans, curr)
for i in range(int(input())):
	a = input()
	lst1 = list(map(int, input().strip().split()))
	lst2 = list(map(int, input().strip().split()))
	lst3 = list(map(int, input().strip().split()))
	print(longest(lst1, lst2, lst3))


t = int(input())
import sys
input = sys.stdin.readline
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lstlen = 0
	ans = 0
	for i in range(1, n):
		curllen = c[i] + 1 + abs(a[i] - b[i])
		if a[i] != b[i]:
			curllen = max(curllen, c[i] + 1 + lstlen - abs(a[i] - b[i]))
		ans = max(ans, curllen)
		lstlen = curllen
	print(ans)


def main():
	for _ in range(int(input())):
		n = int(input())
		c = list(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if n == 1:
			print(0)
			continue
		out = 0
		l = r = 0
		len_l = abs(a[1] - b[1])
		side = 0
		while r < n - 1:
			r += 1
			if r < n - 1:
				len_r = abs(a[r + 1] - b[r + 1])
				side += c[r] - len_r + 1
				now = side + len_r + len_l
				out = max(out, now)
				if len_r == 0 or len_r > side + len_l:
					len_l = len_r
					side = 0
			else:
				len_r = c[r] - 1
				now = side + 2 + len_r + len_l
				out = max(out, now)
		print(out)
main()


def main():
	t = int(input())
	allAns = []
	for _ in range(t):
		n = int(input())
		c = readIntArr()
		a = readIntArr()[1:]
		b = readIntArr()[1:]
		maxOpenLen = [0 for _ in range(n - 1)]
		maxOpenLen[0] = abs(a[0] - b[0])
		ans = 0
		for i in range(1, n - 1):
			ans = max(ans, c[i] - 1 + maxOpenLen[i - 1] + 2)
			(aa, bb) = (min(a[i], b[i]), max(a[i], b[i]))
			if aa < bb:
				maxOpenLen[i] = maxOpenLen[i - 1] + (c[i] - bb) + (aa - 1) + 2
				maxOpenLen[i] = max(maxOpenLen[i], bb - aa)
		ans = max(ans, maxOpenLen[-1] + c[-1] - 1 + 2)
		allAns.append(ans)
	multiLineArrayPrint(allAns)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [0] * n
	for i in range(1, n):
		if b[i] - a[i] == 0:
			dp[i] = 1 + c[i]
		else:
			d = abs(b[i] - a[i])
			dp[i] = 1 + c[i] + max(d, dp[i - 1] - d)
	print(max(dp))


for tc in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = [0]
	for i in range(1, n):
		if a[i] == b[i]:
			k.append(2 + c[i] - 1)
		else:
			n1 = abs(a[i] - b[i]) + 2 + c[i] - 1
			n2 = k[i - 1] - abs(a[i] - b[i]) + 2 + c[i] - 1
			k.append(max(n1, n2))
	print(max(k))


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	for _ in range(int(input())):
		(n,) = aj()
		c = aj()
		a = aj()
		b = aj()
		ans = 0
		tot = c[-1]
		for i in range(n - 1, 0, -1):
			tot += 2
			if a[i] > b[i]:
				(a[i], b[i]) = (b[i], a[i])
			ans = max(ans, tot + b[i] - a[i] - 1)
			if a[i] == b[i]:
				tot = c[i - 1]
			else:
				tot += a[i] - 1
				tot += c[i - 1] - b[i]
			tot = max(tot, c[i - 1])
		print(ans)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
depth = 1000005
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda : list(minp())
minp = lambda : map(int, input().split())
from math import inf, ceil, sqrt, log2
from collections import defaultdict
dd = lambda x: defaultdict(lambda : x)
for _ in range(int(input())):
	n = int(input())
	(c, a, b) = (linp(), linp(), linp())
	(ans, curr) = (0, abs(a[1] - b[1]))
	for i in range(1, n - 1):
		end_here = curr + c[i] + 1
		curr = end_here - abs(a[i + 1] - b[i + 1])
		if a[i + 1] == b[i + 1]:
			curr = 0
		else:
			curr = max(curr, abs(a[i + 1] - b[i + 1]))
		ans = max(ans, end_here)
	end_here = curr + c[n - 1] + 1
	ans = max(ans, end_here)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	c = input().split()
	ci = [int(i) for i in c]
	a = input().split()
	a = a[1:]
	ai = [int(i) for i in a]
	b = input().split()
	b = b[1:]
	bi = [int(i) for i in b]
	dp = [[0, 0] for i in range(n)]
	dp[n - 1][1] = ci[-1] - 1
	for i in range(n - 2, -1, -1):
		dp[i][0] = 2 + dp[i + 1][1]
		if ai[i] != bi[i]:
			dp[i][1] = max(ci[i] - 1, ci[i] - 1 - abs(ai[i] - bi[i]) + 2 + dp[i + 1][1])
		else:
			dp[i][1] = ci[i] - 1
	maxa = 0
	for i in range(n - 1):
		maxa = max(maxa, dp[i][0] + abs(ai[i] - bi[i]))
	print(maxa)


import threading
import sys
threading.stack_size(16 * 2048 * 2048)
sys.setrecursionlimit(100010)

def getnext(index, diff, chain, dp, ans):
	if dp[index] >= 0:
		return dp[index]
	if diff[index] > 0:
		num1 = chain[index] - diff[index] + 1 + getnext(index + 1, diff, chain, dp, ans)
		num2 = chain[index]
		dp[index] = max(num1, num2)
	else:
		dp[index] = chain[index]
	newnum = diff[index] + 1 + getnext(index + 1, diff, chain, dp, ans)
	ans[0] = max(ans[0], newnum)
	return dp[index]

def main():
	T = int(input())
	r = 1
	while r <= T:
		n = int(input())
		chain = list(map(int, input().split()))
		front = list(map(int, input().split()))
		rear = list(map(int, input().split()))
		diff = []
		for i in range(1, n):
			diff.append(abs(front[i] - rear[i]))
		dp = [-1] * n
		dp[-1] = chain[-1]
		ans = [0]
		num = diff[0] + 1 + getnext(1, diff, chain, dp, ans)
		ans[0] = max(ans[0], num)
		print(ans[0])
		r += 1
threading.Thread(target=main).start()


for w in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	ans = 0
	for i in range(1, n):
		if x != 0:
			ans = max(x, ans, x + c[i - 1] - 1)
		if x == 0:
			x = 2 + abs(a[i] - b[i])
		elif a[i] == b[i]:
			x = 2
		else:
			x = max(x + c[i - 1] - 1 - abs(b[i] - a[i]) + 2, abs(b[i] - a[i]) + 2)
		ans = max(ans, x)
	x += c[-1] - 1
	ans = max(ans, x)
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ul = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	ck = abs(ul[1] - ll[1]) + 2
	ans = ck + a[1] - 1
	for i in range(2, n):
		if ul[i] == ll[i]:
			ans = max(ans, ck + a[i - 1] - 1, a[i] + 1)
			ck = 2
		else:
			ck = max(abs(ul[i] - ll[i]), ck + a[i - 1] - 1 - abs(ul[i] - ll[i])) + 2
			ans = max(ans, ck + a[i] - 1)
	print(ans)


import math

def solve(n, a, b, c):
	ans = 0
	prev = 0
	for i in range(1, n):
		cur = c[i] + 1 + abs(a[i] - b[i])
		if a[i] != b[i]:
			cur = max(cur, prev - abs(a[i] - b[i]) + c[i] + 1)
		ans = max(ans, cur)
		prev = cur
	print(ans)
t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, a, b, c)


import math
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	start = list(map(int, input().split()))
	end = list(map(int, input().split()))
	curr_max = abs(start[1] - end[1]) + 1 + arr[1]
	global_max = curr_max
	for i in range(2, n):
		if start[i] == end[i]:
			curr_max = 1 + arr[i]
		else:
			curr_max = max(abs(start[i] - end[i]) + 1 + arr[i], curr_max - abs(end[i] - start[i]) + 1 + arr[i])
		global_max = max(global_max, curr_max)
	print(global_max)
	t -= 1


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()
	C = getInts()
	A = getInts()
	B = getInts()
	lengths = [0]
	start_ind = 0
	best = 0
	D = [(min(a, b), max(a, b), c) for (a, b, c) in zip(A, B, C)]
	D = D[1:]
	prefs = []
	curr = 0
	lengths = [D[i][1] - D[i][0] for i in range(len(D))]
	lengths.append(C[N - 1])
	for i in range(N - 1):
		curr += D[i][0] - 1
		curr += C[i] - D[i][1]
		prefs.append(curr)
	TB = [(a - 1, c - b) for (a, b, c) in D]
	best_start = 0
	for i in range(1, N):
		tmp = C[i] - 1 + lengths[best_start] + 2 * (i - best_start) + prefs[i - 1] - prefs[best_start]
		tmp2 = C[i] - 1 + lengths[i - 1] + 2
		if tmp2 > tmp:
			best_start = i - 1
		best = max(best, tmp, tmp2)
		if lengths[i] == 0:
			best_start = i
	return best
for _ in range(getInt()):
	print(solve())


import os, sys
from io import BytesIO, IOBase
for _ in range(int(input())):
	n = int(input())
	vert = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(dp, ans) = (-10 ** 10, 0)
	for i in range(1, n):
		if a[i] == b[i]:
			dp = 0
		else:
			dp = max(dp + min(a[i], b[i]) - 1 + vert[i - 1] - max(b[i], a[i]) + 2, abs(b[i] - a[i]))
		ans = max(ans, dp + 1 + vert[i])
	print(ans)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase

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
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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, self.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')

def get_int():
	return int(input())

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

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def solve():
	n = get_int()
	c = get_ints()
	a = get_ints()
	b = get_ints()
	dp = [0, abs(a[1] - b[1]) + c[1] + 1]
	for i in range(2, n):
		if a[i] == b[i]:
			dp.append(1 + c[i])
		else:
			dp.append(max(dp[-1] - abs(a[i] - b[i]) + 1 + c[i], 1 + c[i] + abs(a[i] - b[i])))
	return max(dp)
t = int(input())
for _ in range(t):
	print(solve())


for t in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	prev = [0 for i in range(n)]
	best2 = 0
	i = 1
	x = b[i] - a[i]
	if x > 0:
		temp = x + 1
		prev[i] = temp
	elif x == 0:
		prev[i] = 1
	else:
		temp = -x + 1
		prev[i] = temp
	best2 = max(prev[i] + c[i], best2)
	for i in range(2, n):
		x = b[i] - a[i]
		if x > 0:
			temp = max(x + 1, prev[i - 1] + c[i - 1] - x + 1)
			prev[i] = temp
		elif x == 0:
			prev[i] = 1
		else:
			temp = max(-x + 1, prev[i - 1] + c[i - 1] + x + 1)
			prev[i] = temp
		best2 = max(prev[i] + c[i], best2)
	print(best2)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [0 for _ in range(n)]
	for i in range(1, n):
		if a[i] != b[i]:
			dp[i] = max(dp[i - 1] - abs(a[i] - b[i]) + 2 + l[i] - 1, abs(a[i] - b[i]) + 2 + l[i] - 1)
		else:
			dp[i] = 2 + l[i] - 1
	print(max(dp))


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

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

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

def L():
	return list(sp())

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

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

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

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

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
for _ in range(L()[0]):
	n = L()[0]
	A = L()
	x = L()
	y = L()
	ans = 0
	sm = 0
	for i in range(1, n + 1):
		if i == 1:
			sm += abs(y[i] - x[i]) + 1
		elif i != n:
			ans = max(ans, sm + A[i - 1])
			sm += A[i - 1] - (abs(y[i] - x[i]) - int(x[i] != y[i]))
			if x[i] == y[i]:
				ans = max(ans, sm)
				sm = 1
			else:
				sm = max(sm, abs(x[i] - y[i]) + 1)
		else:
			sm += A[-1]
			ans = max(ans, sm)
	print(ans)
endtime = time.time()


def read_input():
	n = int(input())
	chains = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	return (chains, a, b)

def solve(chains, a, b):
	best_dp = [-1]
	if a[1] == b[1]:
		best_dp.append(chains[1] - 1 + 2)
	else:
		best_dp.append(chains[1] - 1 + 2 + abs(a[1] - b[1]))
	best = best_dp[-1]
	for i in range(2, len(chains)):
		if a[i] == b[i]:
			best_dp.append(chains[i] - 1 + 2)
		else:
			diff = abs(a[i] - b[i])
			best_dp.append(chains[i] - 1 + 2 + max(diff, best_dp[i - 1] - diff))
		if best_dp[-1] > best:
			best = best_dp[-1]
	return best
ans = []
t = int(input())
for _ in range(t):
	(chains, a, b) = read_input()
	ans.append(solve(chains, a, b))
	print(solve(chains, a, b))


def solve(n, c, a, b):
	dpr = [0] * n
	dpr[-1] = c[-1] - 1
	for i in range(n - 2, -1, -1):
		stay = c[i] - 1
		if a[i + 1] > b[i + 1]:
			(a[i + 1], b[i + 1]) = (b[i + 1], a[i + 1])
		if a[i + 1] == b[i + 1]:
			nxt = 0
		else:
			nxt = a[i + 1] - 1 + c[i] - b[i + 1] + 2 + dpr[i + 1]
		dpr[i] = max(nxt, stay)
	M = 0
	for i in range(n - 1):
		len_cycle = b[i + 1] - a[i + 1] + 2 + dpr[i + 1]
		M = max(M, len_cycle)
	return M

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		c = list(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print(solve(n, c, a, b))
main()


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	under = [0 for i in range(n)]
	over = [0 for i in range(n)]
	for i in range(1, n):
		under[i - 1] = max(a[i], b[i]) - min(a[i], b[i]) + 1
		over[i - 1] = min(a[i], b[i]) + array[i - 1] - max(a[i], b[i]) + 1
	dp = [0 for i in range(n + 1)]
	i = n - 2
	dp[n - 1] = array[-1]
	maxi = 0
	while i >= 0:
		maxi = max(maxi, dp[i + 1] + under[i])
		if a[i + 1] == b[i + 1]:
			dp[i] = array[i]
		else:
			dp[i] = max(array[i], dp[i + 1] + over[i])
		i -= 1
	print(maxi)


from sys import stdin, stdout
import collections, heapq, bisect, math
input = stdin.readline

def rint():
	return int(input())

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

def rlstr():
	return list(input().strip().split())

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

def main():
	n = rint()
	c = rlint()
	a = rlint()
	b = rlint()
	cur = 0
	res = 0
	for i in range(1, n):
		x = abs(b[i] - a[i])
		if x == 0:
			cur = c[i] + 1
		else:
			cur = max(x, cur - x) + c[i] + 1
		res = max(res, cur)
	print(res)
for _ in range(rint()):
	main()


import sys
input = sys.stdin.readline

def longestSimpleCycle(n, c, a, b):
	(ans, tmp) = (0, abs(a[1] - b[1]))
	for i in range(1, n):
		if a[i] == b[i]:
			tmp = 0
		elif i != 1:
			tmp -= c[i - 1] - 1
			tmp += min(a[i], b[i]) - 1 + c[i - 1] - max(a[i], b[i])
			if abs(a[i] - b[i]) > tmp:
				tmp = abs(a[i] - b[i])
		tmp += c[i] + 1
		ans = max(ans, tmp)
	return ans

def main():
	for t in range(int(input().strip())):
		(n, c, a, b) = (int(input().strip()), [int(i) for i in input().strip().split()], [int(i) for i in input().strip().split()], [int(i) for i in input().strip().split()])
		print(longestSimpleCycle(n, c, a, b))
main()


from math import ceil

def main():
	T = int(input())
	for ___ in range(T):
		n = input().strip()
		n = int(n)
		c = [int(i) for i in input().strip().split()]
		a = [int(i) for i in input().strip().split()]
		b = [int(i) for i in input().strip().split()]
		last_ckpt = 0
		cur_sum = abs(a[1] - b[1])
		ans = 0
		for i in range(1, n):
			if i == n - 1 or a[i + 1] == b[i + 1]:
				cur_sum += 2
				cur_sum += c[i] - 1
				ans = max(ans, cur_sum)
				cur_sum = 0
			else:
				up1 = min(a[i + 1], b[i + 1])
				down1 = max(a[i + 1], b[i + 1])
				cur_sum += 2
				ans = max(ans, cur_sum + c[i] - 1)
				cur_sum += c[i] - (down1 - up1) - 1
				cur_sum = max(cur_sum, down1 - up1)
		print(ans)
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()


a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	maxa = 0
	leng = 0
	for i in range(1, len(a1)):
		if i == 1:
			maxa = max(maxa, z[i] - 1 + abs(a1[i] - a2[i]) + 2)
			if i < len(z) - 1:
				redun = abs(a1[i + 1] - a2[i + 1])
			else:
				redun = 0
			if i < len(z) - 1 and a1[i + 1] == a2[i + 1]:
				leng = 0
				continue
			else:
				leng = z[i] - 1 - redun + abs(a1[i] - a2[i]) + 2
				if i < len(z) - 1:
					leng = max(leng, abs(a1[i + 1] - a2[i + 1]))
		else:
			if i < len(z) - 1:
				redun = abs(a1[i + 1] - a2[i + 1])
			else:
				redun = 0
			maxa = max(maxa, leng + z[i] - 1 + 2)
			if i < len(z) - 1 and a1[i + 1] == a2[i + 1]:
				leng = 0
				continue
			elif i < len(z) - 1 and a1[i + 1] != a2[i + 1]:
				leng += 1 + z[i] - abs(a1[i + 1] - a2[i + 1])
				leng = max(leng, abs(a1[i + 1] - a2[i + 1]))
			else:
				break
	print(maxa)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, l, a, b, best, last, curr) = (int(input()), [int(i) for i in input().split()], [int(i) for i in input().split()], [int(i) for i in input().split()], 0, 0, 0)
	for i in range(1, n):
		curr = 1 + l[i] + abs(a[i] - b[i])
		if a[i] != b[i]:
			curr = max(curr, 1 + l[i] + last - abs(a[i] - b[i]))
		best = max(best, curr)
		last = curr
	print(best)


import sys
import math
t = int(input().strip())
for a0 in range(t):
	n = int(input())
	c = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	dp = []
	for i in range(n + 1):
		dp.append(0)
	for i in range(1, n):
		x = abs(a[i] - b[i])
		x += 2
		x += c[i] - 1
		if a[i] == b[i] or i == 1:
			dp[i] = x
		else:
			dp[i] = x
			min1 = min(a[i], b[i])
			max1 = max(a[i], b[i])
			p1 = min1 - 1
			p2 = c[i - 1] - max1
			ans = c[i] - 1 + p1 + p2 + dp[i - 1] - (c[i - 1] - 1) + 2
			dp[i] = max(dp[i], ans)
	max2 = 0
	flgg = -1
	if dp[0] != 0:
		flgg = 1
	for i in range(1, n):
		max2 = max(max2, dp[i])
	print(max2)


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lst_ans = [0]
	for i in range(1, n):
		x = c[i] + 1
		if a[i] == b[i]:
			lst_ans.append(x)
			continue
		x += max(abs(b[i] - a[i]), lst_ans[i - 1] - abs(a[i] - b[i]))
		lst_ans.append(x)
	print(max(lst_ans))


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(n, c, a, b):
	dp = [0 for i in range(n)]
	ans = 0
	dp[0] = c[0] - 1
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	for i in range(1, n):
		if a[i] == b[i]:
			dp[i] = 2 + (c[i] - 1)
		elif i - 1 != 0:
			dp[i] = max(dp[i - 1] - (c[i - 1] - 1) + c[i] + (c[i - 1] - (b[i] - a[i])), b[i] - a[i] + c[i] + 1)
		else:
			dp[i] = b[i] - a[i] + c[i] + 1
		ans = max(ans, dp[i])
	return ans
t = int(input())
result = []
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	result.append(f(n, c, a, b))
for i in range(t):
	print(result[i])


from sys import stdin, stdout
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd
for _ in range(it()):
	n = it()
	c = mp()
	a = mp()
	b = mp()
	ans = 0
	v = [0] * n
	v[0] = abs(b[1] - a[1])
	v[1] = v[0] + c[1] + 1
	for i in range(2, n):
		if a[i] == b[i]:
			v[i] = c[i] + 1
		else:
			v[i] = max(c[i] + 1 + v[i - 1] - abs(b[i] - a[i]), c[i] + 1 + abs(b[i] - a[i]))
	print(max(v))


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxl = 0
	prc = 0
	prevc = 0
	for i in range(1, n):
		(cc, ca, cb) = (c[i], a[i], b[i])
		if ca == cb:
			prc = 1
		elif prc > 0:
			prc += min(ca, cb) - 1 + (prevc - max(ca, cb))
		pv = abs(ca - cb) + 1
		if pv > prc:
			prc = pv
		cl = prc + cc
		prc += 2
		maxl = max(maxl, cl)
		prevc = cc
	print(maxl)


a = int(input())
for x in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	e = list(map(int, input().split()))
	dp = [c[1] + 1 + abs(d[1] - e[1])]
	for y in range(1, b - 1):
		if abs(d[y + 1] - e[y + 1]) == 0:
			dp.append(c[y + 1] + 1)
		else:
			dp.append(max(c[y + 1] + 1 + dp[y - 1] - abs(d[y + 1] - e[y + 1]), c[y + 1] + 1 + abs(d[y + 1] - e[y + 1])))
	print(max(dp))


def solve():
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	prev = c[1] + abs(b[1] - a[1]) + 1
	ans = prev
	for i in range(2, n):
		if a[i] == b[i]:
			prev = c[i] + 1
		else:
			diff = max(0, abs(b[i] - a[i]) - 1)
			prev = c[i] + max(diff + 2, prev - diff)
		ans = max(prev, ans)
	print(ans)
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	C = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	longestChainLength = 0
	currentChainLength = 0
	for j in range(1, n):
		if j == 1 or A[j] == B[j]:
			currentChainLength = abs(A[j] - B[j]) + 1
		else:
			currentChainLength = max(abs(A[j] - B[j]) + 1, currentChainLength + C[j - 1] - abs(A[j] - B[j]) + 1)
		longestChainLength = max(C[j] + currentChainLength, longestChainLength)
	print(longestChainLength)


test = int(input())
for testcase in range(test):
	n = int(input())
	arr = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	area = arr[n - 1] - 1 + 2 + abs(a[n - 1] - b[n - 1])
	ans = [area]
	for i in range(n - 2, 0, -1):
		if a[i + 1] == b[i + 1]:
			ans.append(arr[i] - 1 + 2 + abs(a[i] - b[i]))
		else:
			ans.append(max(ans[-1] + arr[i] - 1 + 2 + abs(a[i] - b[i]) - 2 * abs(a[i + 1] - b[i + 1]), arr[i] - 1 + 2 + abs(a[i] - b[i])))
	print(max(ans))


t = int(input())
while t:
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(res, tmp) = (0, 0)
	for i in range(1, n):
		abs_v = abs(a[i] - b[i])
		if abs_v == 0:
			tmp = c[i] + 1
		else:
			tmp = max(abs_v, tmp - abs_v)
			tmp += c[i] + 1
		res = max(res, tmp)
	print(res)
	t -= 1


for i in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	max_support = c[n - 1] + 1
	max_length = []
	for i in range(1, n)[::-1]:
		(small, big) = [a[i], b[i]] if a[i] < b[i] else [b[i], a[i]]
		if small == big:
			max_length.append(max_support)
			max_support = c[i - 1] + 1
		else:
			max_length.append(max_support + big - small)
			max_support = max(c[i - 1] + 1 - big + small + max_support, c[i - 1] + 1)
	print(max(max_length))


def main():
	T = eval(input())
	for _ in range(T):
		N = eval(input())
		L = list(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		dp = [0] * N
		for i in range(1, N):
			if a[i] > b[i]:
				(a[i], b[i]) = (b[i], a[i])
			if b[i] == a[i]:
				dp[i] = L[i] + b[i] - a[i] + 1
			else:
				dp[i] = L[i] + b[i] - a[i] + 1
				dp[i] = max(dp[i], dp[i - 1] + L[i] - (b[i] - a[i] - 1))
		ans = max(dp)
		print(ans)
main()


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, 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()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
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('a')

def solve():
	for _ in range(ii()):
		n = ii()
		c = li()
		a = li()
		b = li()
		for i in range(n):
			if a[i] > b[i]:
				(a[i], b[i]) = (b[i], a[i])
		ans = 0
		s = b[1] - a[1] + 1
		for i in range(1, n - 1):
			ans = max(ans, s + c[i])
			c1 = a[i + 1] + c[i] - b[i + 1]
			s = max(b[i + 1] - a[i + 1], s + c1)
			if a[i + 1] == b[i + 1]:
				s = 0
			s += 1
		ans = max(ans, s + c[-1])
		print(ans)
solve()


from math import ceil
t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	summ = 0
	ans = 0
	for i in range(1, n):
		if a[i] != b[i] and i != 1:
			summ += c[i - 1] - max(a[i], b[i]) + min(a[i], b[i]) + 1
		else:
			summ = 0
		summ = max(summ, abs(a[i] - b[i]) + 2)
		ans = max(ans, c[i] + summ - 1)
	print(ans)