N = int(eval(input()))

S = []

for _ in range(N):

    D = list(map(int, input().split()))

    S.append(D)



import numpy as np

#dp=np.zeros((N+1,3))



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



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

    for j in range(3):

        for k in range(3):

            if j != k:

                happy =  dp[i-1][k] + S[i-1][j]

                if dp[i][j] < happy:

                    dp[i][j] = happy



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

S = []

for _ in range(N):

    D = list(map(int, input().split()))

    S.append(D)



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



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

    for j in range(3):

        for k in range(3):

            if j != k:

                happy =  dp[i-1][k] + S[i-1][j]

                if dp[i][j] < happy:

                    dp[i][j] = happy



print((int(max(dp[N]))))
N = int(eval(input()))
S = []
for _ in range(N):
    D = list(map(int, input().split()))
    S.append(D)
import numpy as np

# dp=np.zeros((N+1,3))
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                happy = dp[i - 1][k] + S[i - 1][j]
                if dp[i][j] < happy:
                    dp[i][j] = happy
print((int(max(dp[N]))))

N = int(eval(input()))
S = []
for _ in range(N):
    D = list(map(int, input().split()))
    S.append(D)
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                happy = dp[i - 1][k] + S[i - 1][j]
                if dp[i][j] < happy:
                    dp[i][j] = happy
print((int(max(dp[N]))))

-import numpy as np - -# dp=np.zeros((N+1,3))