N = int(eval(input()))

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



dp = [[0]*3 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] + src[i][k])

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

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



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

dp[0] = src[0]

for i,(a,b,c) in enumerate(src[1:]):

    dp[i+1][0] = a + max(dp[i][1], dp[i][2])

    dp[i+1][1] = b + max(dp[i][2], dp[i][0])

    dp[i+1][2] = c + max(dp[i][0], dp[i][1])

print((max(dp[-1])))
N = int(eval(input()))
src = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0] * 3 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] + src[i][k])
print((max(dp[-1])))

N = int(eval(input()))
src = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0] * 3 for i in range(N)]
dp[0] = src[0]
for i, (a, b, c) in enumerate(src[1:]):
    dp[i + 1][0] = a + max(dp[i][1], dp[i][2])
    dp[i + 1][1] = b + max(dp[i][2], dp[i][0])
    dp[i + 1][2] = c + max(dp[i][0], dp[i][1])
print((max(dp[-1])))

-dp = [[0] * 3 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] + src[i][k]) +dp = [[0] * 3 for i in range(N)] +dp[0] = src[0] +for i, (a, b, c) in enumerate(src[1:]): +    dp[i + 1][0] = a + max(dp[i][1], dp[i][2]) +    dp[i + 1][1] = b + max(dp[i][2], dp[i][0]) +    dp[i + 1][2] = c + max(dp[i][0], dp[i][1])