N=int(eval(input()))

act=[]

for i in range(N):

    act.append(list(map(int,input().split())))

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



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

    for j in range(3):

        for k in range(3):

            if(j!=k):

                dp[i][j]=max(dp[i][j],dp[i-1][k]+act[i-1][j])

                

print((max([dp[N][0],dp[N][1],dp[N][2]])))
N=int(eval(input()))

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

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

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

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

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

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

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

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

-act = [] -for i in range(N): -    act.append(list(map(int, input().split()))) -dp = [[0] * 3 for i in range(N + 1)] +dp = [[0, 0, 0] for i in range(N + 1)] -    for j in range(3): -        for k in range(3): -            if j != k: -                dp[i][j] = max(dp[i][j], dp[i - 1][k] + act[i - 1][j]) -print((max([dp[N][0], dp[N][1], dp[N][2]]))) +    a, b, c = list(map(int, input().split())) +    dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a) +    dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b) +    dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c) +print((max(dp[N])))