Help me in solving ATBO problem

My issue

All of the test cases are correct except the last one. Could someone tell me what’s wrong in my code?

My code

for _ in range(int(input())):
    n = int(input().strip())
    a = list(map(int,input().strip().split()))
    b = list(map(int,input().strip().split()))
    flag = True
    for i in range(n-3):
        if a[i]==b[i]:
            continue
        elif b[i]==a[i]+a[i+1]+a[i+2]:
            n1,n2,n3,n4 = a[i],a[i+1],a[i+2],a[i+3]
            a[i]=n1+n2+n3
            a[i+1]=-n3
            a[i+2]=-n2
            a[i+3]=n2+n3+n4

        else:
            flag = False
            break

    if flag:
        if a!=b:
            print('NO')
        else:
            print('YES')
    else:
        print('NO')

Problem Link: Operating on A Practice Coding Problem - CodeChef