N = int(eval(input()))

A = [[int(i) for i in input().split()] for _ in range(N)]



x = y = z = 0

for a, b, c in A:

  x, y, z = max(y, z)+a, max(x,z)+b, max(x,y)+c

print((max(x, y, z)))
N = int(eval(input()))



x = y = z = 0

for _ in range(N):

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

  x, y, z = max(y, z)+a, max(x,z)+b, max(x,y)+c

print((max(x, y, z)))
N = int(eval(input()))
A = [[int(i) for i in input().split()] for _ in range(N)]
x = y = z = 0
for a, b, c in A:
    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
print((max(x, y, z)))

N = int(eval(input()))
x = y = z = 0
for _ in range(N):
    a, b, c = list(map(int, input().split()))
    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
print((max(x, y, z)))

-A = [[int(i) for i in input().split()] for _ in range(N)] -for a, b, c in A: +for _ in range(N): +    a, b, c = list(map(int, input().split()))