N = int(eval(input()))



dp = [[0 for _ in range(3)] for _ in range(N)]



a,b,c = [int(i) for i in input().split()]

dp[0][0] = a

dp[0][1] = b

dp[0][2] = c



for i in range(1,N):

    li = [int(i) for i in input().split()]

    for j in range(3):

        tmp = []

        for k in range(3):

            if j != k:

                tmp.append(dp[i-1][k] + li[j])

        dp[i][j] = max(tmp)



print((max(dp[-1])))

N = int(eval(input()))

A = [[int(i) for i in input().split()] for _ in range(N)]



dp = [[0]*3 for _ in range(N)]

dp[0] = A[0]



for i in range(1,N):

    for j in range(3):

        for k in range(3):

            if j != k:

                dp[i][k] = max(dp[i][k], dp[i-1][j]+A[i][k])



print((max(dp[-1])))

N = int(eval(input()))
dp = [[0 for _ in range(3)] for _ in range(N)]
a, b, c = [int(i) for i in input().split()]
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c
for i in range(1, N):
    li = [int(i) for i in input().split()]
    for j in range(3):
        tmp = []
        for k in range(3):
            if j != k:
                tmp.append(dp[i - 1][k] + li[j])
        dp[i][j] = max(tmp)
print((max(dp[-1])))

N = int(eval(input()))
A = [[int(i) for i in input().split()] for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0] = A[0]
for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i - 1][j] + A[i][k])
print((max(dp[-1])))

-dp = [[0 for _ in range(3)] for _ in range(N)] -a, b, c = [int(i) for i in input().split()] -dp[0][0] = a -dp[0][1] = b -dp[0][2] = c +A = [[int(i) for i in input().split()] for _ in range(N)] +dp = [[0] * 3 for _ in range(N)] +dp[0] = A[0] -    li = [int(i) for i in input().split()] -        tmp = [] -                tmp.append(dp[i - 1][k] + li[j]) -        dp[i][j] = max(tmp) +                dp[i][k] = max(dp[i][k], dp[i - 1][j] + A[i][k])