n = int(eval(input()))

a = [0] * (n + 1)

b = [0] * (n + 1)

c = [0] * (n + 1)

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

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

    a[i] = a[i] + max(b[i - 1], c[i - 1])

    b[i] = b[i] + max(c[i - 1], a[i - 1])

    c[i] = c[i] + max(a[i - 1], b[i - 1])

print((max(a[n], b[n], c[n])))
n = int(eval(input()))

hya, hyb, hyc = 0, 0, 0

for _ in range(n):

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

    ha = a + max(hyb, hyc)

    hb = b + max(hyc, hya)

    hc = c + max(hya, hyb)

    hya =ha

    hyb =hb

    hyc =hc

print((max(ha, hb, hc)))
n = int(eval(input()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int, input().split()))
    a[i] = a[i] + max(b[i - 1], c[i - 1])
    b[i] = b[i] + max(c[i - 1], a[i - 1])
    c[i] = c[i] + max(a[i - 1], b[i - 1])
print((max(a[n], b[n], c[n])))

n = int(eval(input()))
hya, hyb, hyc = 0, 0, 0
for _ in range(n):
    a, b, c = list(map(int, input().split()))
    ha = a + max(hyb, hyc)
    hb = b + max(hyc, hya)
    hc = c + max(hya, hyb)
    hya = ha
    hyb = hb
    hyc = hc
print((max(ha, hb, hc)))

-a = [0] * (n + 1) -b = [0] * (n + 1) -c = [0] * (n + 1) -for i in range(1, n + 1): -    a[i], b[i], c[i] = list(map(int, input().split())) -    a[i] = a[i] + max(b[i - 1], c[i - 1]) -    b[i] = b[i] + max(c[i - 1], a[i - 1]) -    c[i] = c[i] + max(a[i - 1], b[i - 1]) -print((max(a[n], b[n], c[n]))) +hya, hyb, hyc = 0, 0, 0 +for _ in range(n): +    a, b, c = list(map(int, input().split())) +    ha = a + max(hyb, hyc) +    hb = b + max(hyc, hya) +    hc = c + max(hya, hyb) +    hya = ha +    hyb = hb +    hyc = hc +print((max(ha, hb, hc)))