n = int(eval(input()))

dp = [0] * 3

for i in range(n):

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

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

print((max(dp)))
N = int(eval(input()))

dp = [0, 0, 0]

for i in range(N):

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

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

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

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

    dp = [tmp_a, tmp_b, tmp_c]

print((max(dp)))

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

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

-n = int(eval(input())) -dp = [0] * 3 -for i in range(n): +N = int(eval(input())) +dp = [0, 0, 0] +for i in range(N): -    dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])] +    tmp_a = a + max(dp[1], dp[2]) +    tmp_b = b + max(dp[0], dp[2]) +    tmp_c = c + max(dp[0], dp[1]) +    dp = [tmp_a, tmp_b, tmp_c]