N = int(eval(input()))

plans = [list(map(int, input().split())) for _ in range(N)]

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



def chmax(a, b):

    if a >= b:

        return a

    else:

        return b



for i in range(N):

    for j in range(3):

        for k in range(3):

            if j == k:

                continue

            else:

                dp[i+1][k] = chmax(dp[i+1][k], dp[i][j] + plans[i][k])

                

res = 0

for j in range(3):

    res = chmax(res, dp[-1][j])

print(res)
N = int(eval(input()))

h = [list(map(int, input().split())) for _ in range(N)] #1-index



def chmax(a,b):

    if a >= b:

        return a

    else:

        return b

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

for i in range(N):

    for j in range(3):

        for k in range(3):

            if (j == k): continue

            dp[i+1][k] = chmax(dp[i+1][k], dp[i][j] + h[i][k])



print((max(dp[N])))
N = int(eval(input()))
plans = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (3) for _ in range(N + 1)]


def chmax(a, b):
    if a >= b:
        return a
    else:
        return b


for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            else:
                dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + plans[i][k])
res = 0
for j in range(3):
    res = chmax(res, dp[-1][j])
print(res)

N = int(eval(input()))
h = [list(map(int, input().split())) for _ in range(N)]  # 1-index


def chmax(a, b):
    if a >= b:
        return a
    else:
        return b


dp = [[0] * (3) for _ in range(N + 2)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + h[i][k])
print((max(dp[N])))

-plans = [list(map(int, input().split())) for _ in range(N)] -dp = [[0] * (3) for _ in range(N + 1)] +h = [list(map(int, input().split())) for _ in range(N)]  # 1-index +dp = [[0] * (3) for _ in range(N + 2)] -            else: -                dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + plans[i][k]) -res = 0 -for j in range(3): -    res = chmax(res, dp[-1][j]) -print(res) +            dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + h[i][k]) +print((max(dp[N])))