days = int(eval(input()))



prev = [0, 0, 0]

while days:

    nxt = [0, 0, 0]

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

    nxt[0] = a + max(prev[1], prev[2])

    nxt[1] = b + max(prev[0], prev[2])

    nxt[2] = c + max(prev[0], prev[1])

    prev = nxt

    days -= 1



print((max(prev)))
import sys

# read = sys.stdin.read

input = sys.stdin.readline

# readlines = sys.stdin.readlines

days = int(eval(input()))



prev = [0, 0, 0]

while days:

    nxt = [0, 0, 0]

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

    nxt[0] = a + max(prev[1], prev[2])

    nxt[1] = b + max(prev[0], prev[2])

    nxt[2] = c + max(prev[0], prev[1])

    prev = nxt

    days -= 1



print((max(prev)))
days = int(eval(input()))
prev = [0, 0, 0]
while days:
    nxt = [0, 0, 0]
    a, b, c = list(map(int, input().split()))
    nxt[0] = a + max(prev[1], prev[2])
    nxt[1] = b + max(prev[0], prev[2])
    nxt[2] = c + max(prev[0], prev[1])
    prev = nxt
    days -= 1
print((max(prev)))

import sys

# read = sys.stdin.read
input = sys.stdin.readline
# readlines = sys.stdin.readlines
days = int(eval(input()))
prev = [0, 0, 0]
while days:
    nxt = [0, 0, 0]
    a, b, c = list(map(int, input().split()))
    nxt[0] = a + max(prev[1], prev[2])
    nxt[1] = b + max(prev[0], prev[2])
    nxt[2] = c + max(prev[0], prev[1])
    prev = nxt
    days -= 1
print((max(prev)))

+import sys + +# read = sys.stdin.read +input = sys.stdin.readline +# readlines = sys.stdin.readlines