#l=list(map(int,input().split()))
for abcd in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans=0
    for i in a:
        if(i in b):
            ans=i
            break
    if(ans!=0):
        print("YES")
        print(1,ans,end=" ")
        print()
    else:
        print("NO")
    
        
        
