n=int(eval(input()))

dp=[[0]*3 for _ in range(n)]

dp[0]=list(map(int,input().split()))

for i in range(1,n):

    l=list(map(int,input().split()))

    dp[i][0]=l[0]+max(dp[i-1][1],dp[i-1][2])

    dp[i][1]=l[1]+max(dp[i-1][0],dp[i-1][2])

    dp[i][2]=l[2]+max(dp[i-1][0],dp[i-1][1])

print((max(dp[-1])))
A=B=C=0;M=max

for i in range(int(eval(input()))):

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

    A,B,C=a+M(B,C),b+M(C,A),c+M(A,B)

print((M(A,B,C)))
n = int(eval(input()))
dp = [[0] * 3 for _ in range(n)]
dp[0] = list(map(int, input().split()))
for i in range(1, n):
    l = list(map(int, input().split()))
    dp[i][0] = l[0] + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = l[1] + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = l[2] + max(dp[i - 1][0], dp[i - 1][1])
print((max(dp[-1])))

A = B = C = 0
M = max
for i in range(int(eval(input()))):
    a, b, c = list(map(int, input().split()))
    A, B, C = a + M(B, C), b + M(C, A), c + M(A, B)
print((M(A, B, C)))

-n = int(eval(input())) -dp = [[0] * 3 for _ in range(n)] -dp[0] = list(map(int, input().split())) -for i in range(1, n): -    l = list(map(int, input().split())) -    dp[i][0] = l[0] + max(dp[i - 1][1], dp[i - 1][2]) -    dp[i][1] = l[1] + max(dp[i - 1][0], dp[i - 1][2]) -    dp[i][2] = l[2] + max(dp[i - 1][0], dp[i - 1][1]) -print((max(dp[-1]))) +A = B = C = 0 +M = max +for i in range(int(eval(input()))): +    a, b, c = list(map(int, input().split())) +    A, B, C = a + M(B, C), b + M(C, A), c + M(A, B) +print((M(A, B, C)))