n = int(eval(input()))

s = [list(map(int, input().split())) for _ 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][j] + s[i][k], dp[i+1][k])



print((max(dp[n])))

n = int(eval(input()))

abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0, 0, 0] for _ in range(2 * n)]



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] + abc[i][k])



print((max(dp[n])))

n = int(eval(input()))
s = [list(map(int, input().split())) for _ 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][j] + s[i][k], dp[i + 1][k])
print((max(dp[n])))

n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(2 * n)]
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] + abc[i][k])
print((max(dp[n])))

-s = [list(map(int, input().split())) for _ in range(n)] -dp = [[0] * 3 for i in range(n + 1)] +abc = [list(map(int, input().split())) for _ in range(n)] +dp = [[0, 0, 0] for _ in range(2 * n)] -            dp[i + 1][k] = max(dp[i][j] + s[i][k], dp[i + 1][k]) +            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k])