N = int(eval(input()))

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

for i in range(N):

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

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

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

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

print((max(dp[N])))

N = int(eval(input()))

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



for i in range(N):

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

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

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

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



print((max(dp[N])))

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

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

-dp = [[0 for i in range(3)] for i in range(N + 1)] +dp = [[0] * 3 for i in range(N + 1)] -    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a -    dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b -    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c +    dp[i + 1][0] = max(dp[i][1] + a, dp[i][2] + a, dp[i][0]) +    dp[i + 1][1] = max(dp[i][2] + b, dp[i][0] + b, dp[i][1]) +    dp[i + 1][2] = max(dp[i][0] + c, dp[i][1] + c, dp[i][2])