N=int(eval(input()))

dp=[list(map(int,input().split()))]

for _ in range(1,N):

    a,b,c=list(map(int,input().split()))

    dp.append([a+max(dp[-1][1:]),b+max(dp[-1][0],dp[-1][2]),c+max(dp[-1][:2])])

print((max(dp[-1])))
N=int(eval(input()))

a0,b0,c0=list(map(int,input().split()))

for _ in range(1,N):

    a,b,c=list(map(int,input().split()))

    a0,b0,c0=a+max(b0,c0),b+max(a0,c0),c+max(a0,b0)

print((max(a0,b0,c0)))
N = int(eval(input()))
dp = [list(map(int, input().split()))]
for _ in range(1, N):
    a, b, c = list(map(int, input().split()))
    dp.append([a + max(dp[-1][1:]), b + max(dp[-1][0], dp[-1][2]), c + max(dp[-1][:2])])
print((max(dp[-1])))

N = int(eval(input()))
a0, b0, c0 = list(map(int, input().split()))
for _ in range(1, N):
    a, b, c = list(map(int, input().split()))
    a0, b0, c0 = a + max(b0, c0), b + max(a0, c0), c + max(a0, b0)
print((max(a0, b0, c0)))

-dp = [list(map(int, input().split()))] +a0, b0, c0 = list(map(int, input().split())) -    dp.append([a + max(dp[-1][1:]), b + max(dp[-1][0], dp[-1][2]), c + max(dp[-1][:2])]) -print((max(dp[-1]))) +    a0, b0, c0 = a + max(b0, c0), b + max(a0, c0), c + max(a0, b0) +print((max(a0, b0, c0)))