N = int(eval(input()))

A, B, C = [], [], []

for n in range(N):

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

    A.append(a)

    B.append(b)

    C.append(c)

a, b, c = 0, 0, 0

for n in range(N):

    a, b, c = A[n] + max(b, c), B[n] + max(c, a), C[n] + max(a, b)

print((max(a, b, c)))

N = int(eval(input()))

a, b, c = 0, 0, 0

for n in range(N):

    an, bn, cn = list(map(int, input().split()))

    a, b, c = an + max(b, c), bn + max(c, a), cn + max(a, b)

print((max(a, b, c)))

N = int(eval(input()))
A, B, C = [], [], []
for n in range(N):
    a, b, c = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    C.append(c)
a, b, c = 0, 0, 0
for n in range(N):
    a, b, c = A[n] + max(b, c), B[n] + max(c, a), C[n] + max(a, b)
print((max(a, b, c)))

N = int(eval(input()))
a, b, c = 0, 0, 0
for n in range(N):
    an, bn, cn = list(map(int, input().split()))
    a, b, c = an + max(b, c), bn + max(c, a), cn + max(a, b)
print((max(a, b, c)))

-A, B, C = [], [], [] -for n in range(N): -    a, b, c = list(map(int, input().split())) -    A.append(a) -    B.append(b) -    C.append(c) -    a, b, c = A[n] + max(b, c), B[n] + max(c, a), C[n] + max(a, b) +    an, bn, cn = list(map(int, input().split())) +    a, b, c = an + max(b, c), bn + max(c, a), cn + max(a, b)