N = int(eval(input()))

L = []

for i in range(N) :

    L.append(list(map(int,input().split())))



dp = [[0,0,0] for i in range(N+1)]



for i in range(N) :

    for j in range(3) :

        for k in range(3) :

            if j == k :

                continue

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

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

N = int(eval(input()))

L = [list(map(int,input().split())) for i in range(N)]

NOW = [0,0,0]

NEXT = [None,None,None]



for i in range(N) :

    NEXT[0] = max(NOW[1],NOW[2]) + L[i][0]

    NEXT[1] = max(NOW[2],NOW[0]) + L[i][1]

    NEXT[2] = max(NOW[0],NOW[1]) + L[i][2]

    

    NOW = NEXT.copy()

print((max(NOW)))

N = int(eval(input()))
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
dp = [[0, 0, 0] for i in range(N + 1)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + L[i][k])
print((max(dp[-1])))

N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
NOW = [0, 0, 0]
NEXT = [None, None, None]
for i in range(N):
    NEXT[0] = max(NOW[1], NOW[2]) + L[i][0]
    NEXT[1] = max(NOW[2], NOW[0]) + L[i][1]
    NEXT[2] = max(NOW[0], NOW[1]) + L[i][2]
    NOW = NEXT.copy()
print((max(NOW)))

-L = [] +L = [list(map(int, input().split())) for i in range(N)] +NOW = [0, 0, 0] +NEXT = [None, None, None] -    L.append(list(map(int, input().split()))) -dp = [[0, 0, 0] for i in range(N + 1)] -for i in range(N): -    for j in range(3): -        for k in range(3): -            if j == k: -                continue -            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + L[i][k]) -print((max(dp[-1]))) +    NEXT[0] = max(NOW[1], NOW[2]) + L[i][0] +    NEXT[1] = max(NOW[2], NOW[0]) + L[i][1] +    NEXT[2] = max(NOW[0], NOW[1]) + L[i][2] +    NOW = NEXT.copy() +print((max(NOW)))