n = int(eval(input()))



dpa, dpb, dpc = 0, 0, 0



for i in range(n):

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

    dpa, dpb, dpc = max(dpb, dpc) + a, max(dpa, dpc) + b, max(dpa, dpb) + c



print((max(dpa, dpb, dpc)))

n = int(eval(input()))

da, db, dc = 0, 0, 0



for i in range(n):

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

    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c



print((max(da, db, dc)))

n = int(eval(input()))
dpa, dpb, dpc = 0, 0, 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    dpa, dpb, dpc = max(dpb, dpc) + a, max(dpa, dpc) + b, max(dpa, dpb) + c
print((max(dpa, dpb, dpc)))

n = int(eval(input()))
da, db, dc = 0, 0, 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c
print((max(da, db, dc)))

-dpa, dpb, dpc = 0, 0, 0 +da, db, dc = 0, 0, 0 -    dpa, dpb, dpc = max(dpb, dpc) + a, max(dpa, dpc) + b, max(dpa, dpb) + c -print((max(dpa, dpb, dpc))) +    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c +print((max(da, db, dc)))