Help me in solving CS2023_STK problem

My issue

can someone explain me where my code is going wrong?

My code

# cook your dish here
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    A=[]
    B=[]
    p=0
    q=0
    for x in a:
        if x==0 or a[n-1]!=0:
            A.append(p)
            p=0
        else:
            p+=1
    for x in b:
        if x==0 or b[n-1]!=0:
            B.append(q)
            q=0
        else:
            q+=1
    if max(A)>max(B):
        print('Om')
    elif max(A)==max(B):
        print('Draw')
    else:
        print('Addy')

Problem Link: CS2023_STK Problem - CodeChef

@ashay21
Just a little logical mistake.
I have corrected it in your code . Hope u will get it.

# cook your dish here
# cook your dish here
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    A=[]
    B=[]
    p=0
    q=0
    for x in a:
        if x==0:
            A.append(p)
            p=0
        else:
            p+=1
    for x in b:
        if x==0:
            B.append(q)
            q=0
        else:
            q+=1
    A.append(p);
    B.append(q);
    if max(A)>max(B):
        print('Om')
    elif max(A)==max(B):
        print('Draw')
    else:
        print('Addy')