N = int(eval(input()))

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



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



for n in range(N):

	for j in range(3):

		for k in range(3):

			if j == k:

				continue

			dp[n + 1][j] = max([dp[n + 1][j], dp[n][k] + ABC[n][j]])

	#print(dp)

print((max(dp[N])))

N = int(eval(input()))

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



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



for n, p in enumerate(ABC):

	dp[n + 1][0] = max(dp[n + 1][0], dp[n][1] + p[0], dp[n][2] + p[0])

	dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + p[1], dp[n][2] + p[1])

	dp[n + 1][2] = max(dp[n + 1][2], dp[n][0] + p[2], dp[n][1] + p[2])



#for line in dp:

#	print(*line)



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

N = int(eval(input()))
ABC = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N + 1)]
for n in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[n + 1][j] = max([dp[n + 1][j], dp[n][k] + ABC[n][j]])
    # print(dp)
print((max(dp[N])))

N = int(eval(input()))
ABC = [list(map(int, input().split())) for _ in range(N)]
dp = [[0, 0, 0] for _ in range(N + 1)]
for n, p in enumerate(ABC):
    dp[n + 1][0] = max(dp[n + 1][0], dp[n][1] + p[0], dp[n][2] + p[0])
    dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + p[1], dp[n][2] + p[1])
    dp[n + 1][2] = max(dp[n + 1][2], dp[n][0] + p[2], dp[n][1] + p[2])
# for line in dp:
# 	print(*line)
print((max(dp[-1])))

-dp = [[0] * 3 for _ in range(N + 1)] -for n in range(N): -    for j in range(3): -        for k in range(3): -            if j == k: -                continue -            dp[n + 1][j] = max([dp[n + 1][j], dp[n][k] + ABC[n][j]]) -    # print(dp) -print((max(dp[N]))) +dp = [[0, 0, 0] for _ in range(N + 1)] +for n, p in enumerate(ABC): +    dp[n + 1][0] = max(dp[n + 1][0], dp[n][1] + p[0], dp[n][2] + p[0]) +    dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + p[1], dp[n][2] + p[1]) +    dp[n + 1][2] = max(dp[n + 1][2], dp[n][0] + p[2], dp[n][1] + p[2]) +# for line in dp: +# 	print(*line) +print((max(dp[-1])))