n = int(eval(input()))



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

for i in range(1,n+1):

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

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

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

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

    dp.append([x,y,z])

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

n = int(eval(input()))



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

for i in range(1,n+1):

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

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

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

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

    dp = [x,y,z]

print((max(dp)))

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

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

-dp = [[0 for i in range(3)]] +dp = [0 for i in range(3)] -    x = max(dp[i - 1][1] + a, dp[i - 1][2] + a) -    y = max(dp[i - 1][2] + b, dp[i - 1][0] + b) -    z = max(dp[i - 1][0] + c, dp[i - 1][1] + c) -    dp.append([x, y, z]) -print((max(dp[n]))) +    x = max(dp[1] + a, dp[2] + a) +    y = max(dp[2] + b, dp[0] + b) +    z = max(dp[0] + c, dp[1] + c) +    dp = [x, y, z] +print((max(dp)))