n = int(eval(input()))

abc = [list(map(int, input().split())) for _ in range(n)]



aabbcc = [[0], [0], [0]]

tmp = [0]*3

for i in abc:

  for j in range(3):

    tmp[j] = i[j] + max(aabbcc[(j+1)%3][-1], aabbcc[(j+2)%3][-1])

  for j in range(3):

    aabbcc[j].append(tmp[j])

print((max([i[-1] for i in aabbcc])))
n = int(eval(input()))

abc = [list(map(int, input().split())) for _ in range(n)]



a, b, c = [0], [0], [0]

for i in abc:

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

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

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

  a.append(aa)

  b.append(bb)

  c.append(cc)

print((max(a[-1], b[-1], c[-1])))
n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n)]
aabbcc = [[0], [0], [0]]
tmp = [0] * 3
for i in abc:
    for j in range(3):
        tmp[j] = i[j] + max(aabbcc[(j + 1) % 3][-1], aabbcc[(j + 2) % 3][-1])
    for j in range(3):
        aabbcc[j].append(tmp[j])
print((max([i[-1] for i in aabbcc])))

n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n)]
a, b, c = [0], [0], [0]
for i in abc:
    aa = i[0] + max(b[-1], c[-1])
    bb = i[1] + max(c[-1], a[-1])
    cc = i[2] + max(a[-1], b[-1])
    a.append(aa)
    b.append(bb)
    c.append(cc)
print((max(a[-1], b[-1], c[-1])))

-aabbcc = [[0], [0], [0]] -tmp = [0] * 3 +a, b, c = [0], [0], [0] -    for j in range(3): -        tmp[j] = i[j] + max(aabbcc[(j + 1) % 3][-1], aabbcc[(j + 2) % 3][-1]) -    for j in range(3): -        aabbcc[j].append(tmp[j]) -print((max([i[-1] for i in aabbcc]))) +    aa = i[0] + max(b[-1], c[-1]) +    bb = i[1] + max(c[-1], a[-1]) +    cc = i[2] + max(a[-1], b[-1]) +    a.append(aa) +    b.append(bb) +    c.append(cc) +print((max(a[-1], b[-1], c[-1])))