n = int(eval(input()))

ls = [(0,0,0)]

for _ in range(n):

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

    ls.append((a,b,c))



dpa = [0]*(n+1)

dpb = [0]*(n+1)

dpc = [0]*(n+1)



for x in range(1,n+1):

    a,b,c = ls[x]

    dpa[x] = max(dpc[x-1]+a,dpb[x-1]+a)

    dpb[x] = max(dpa[x-1]+b,dpc[x-1]+b)

    dpc[x] = max(dpa[x-1]+c,dpb[x-1]+c)





print((max(dpa[-1],dpb[-1],dpc[-1])))

n = int(eval(input()))

ls = [(0,0,0)]

for _ in range(n):

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

    ls.append((a,b,c))



dpa = 0

dpb = 0

dpc = 0



for x in range(1,n+1):

    a,b,c = ls[x]

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





print((max(dpa,dpb,dpc)))
n = int(eval(input()))
ls = [(0, 0, 0)]
for _ in range(n):
    a, b, c = list(map(int, input().split()))
    ls.append((a, b, c))
dpa = [0] * (n + 1)
dpb = [0] * (n + 1)
dpc = [0] * (n + 1)
for x in range(1, n + 1):
    a, b, c = ls[x]
    dpa[x] = max(dpc[x - 1] + a, dpb[x - 1] + a)
    dpb[x] = max(dpa[x - 1] + b, dpc[x - 1] + b)
    dpc[x] = max(dpa[x - 1] + c, dpb[x - 1] + c)
print((max(dpa[-1], dpb[-1], dpc[-1])))

n = int(eval(input()))
ls = [(0, 0, 0)]
for _ in range(n):
    a, b, c = list(map(int, input().split()))
    ls.append((a, b, c))
dpa = 0
dpb = 0
dpc = 0
for x in range(1, n + 1):
    a, b, c = ls[x]
    dpa, dpb, dpc = max(dpc + a, dpb + a), max(dpa + b, dpc + b), max(dpa + c, dpb + c)
print((max(dpa, dpb, dpc)))

-dpa = [0] * (n + 1) -dpb = [0] * (n + 1) -dpc = [0] * (n + 1) +dpa = 0 +dpb = 0 +dpc = 0 -    dpa[x] = max(dpc[x - 1] + a, dpb[x - 1] + a) -    dpb[x] = max(dpa[x - 1] + b, dpc[x - 1] + b) -    dpc[x] = max(dpa[x - 1] + c, dpb[x - 1] + c) -print((max(dpa[-1], dpb[-1], dpc[-1]))) +    dpa, dpb, dpc = max(dpc + a, dpb + a), max(dpa + b, dpc + b), max(dpa + c, dpb + c) +print((max(dpa, dpb, dpc)))