N = int(eval(input()))

H = []

for _ in range(N):

    h = tuple(map(int, input().split()))

    H.append(h)



dp = [H[0]]

for i in range(1, N):

    dp.append([

        max(dp[i-1][1] + H[i][0], dp[i-1][2] + H[i][0]),

        max(dp[i-1][0] + H[i][1], dp[i-1][2] + H[i][1]),

        max(dp[i-1][0] + H[i][2], dp[i-1][1] + H[i][2]),

    ])

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

N = int(eval(input()))

H = []

for _ in range(N):

    h = tuple(map(int, input().split()))

    H.append(h)



dp = H[0]

for i in range(1, N):

    a, b, c = H[i]

    dp_next = [

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

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

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

    ]

    dp = dp_next



print((max(dp)))
N = int(eval(input()))
H = []
for _ in range(N):
    h = tuple(map(int, input().split()))
    H.append(h)
dp = [H[0]]
for i in range(1, N):
    dp.append(
        [
            max(dp[i - 1][1] + H[i][0], dp[i - 1][2] + H[i][0]),
            max(dp[i - 1][0] + H[i][1], dp[i - 1][2] + H[i][1]),
            max(dp[i - 1][0] + H[i][2], dp[i - 1][1] + H[i][2]),
        ]
    )
print((max(dp[-1])))

N = int(eval(input()))
H = []
for _ in range(N):
    h = tuple(map(int, input().split()))
    H.append(h)
dp = H[0]
for i in range(1, N):
    a, b, c = H[i]
    dp_next = [
        max(dp[1] + a, dp[2] + a),
        max(dp[0] + b, dp[2] + b),
        max(dp[0] + c, dp[1] + c),
    ]
    dp = dp_next
print((max(dp)))

-dp = [H[0]] +dp = H[0] -    dp.append( -        [ -            max(dp[i - 1][1] + H[i][0], dp[i - 1][2] + H[i][0]), -            max(dp[i - 1][0] + H[i][1], dp[i - 1][2] + H[i][1]), -            max(dp[i - 1][0] + H[i][2], dp[i - 1][1] + H[i][2]), -        ] -    ) -print((max(dp[-1]))) +    a, b, c = H[i] +    dp_next = [ +        max(dp[1] + a, dp[2] + a), +        max(dp[0] + b, dp[2] + b), +        max(dp[0] + c, dp[1] + c), +    ] +    dp = dp_next +print((max(dp)))