t=int(input())
for _ in range(t):
    n1,n2=map(int,input().split())
    li1=list(map(int,input().split()))
    li2=list(map(int,input().split()))
    s=set()
    ans=-1
    for i in li1:
        s.add(i)
    for i in li2:
        if(i in s):
            ans=i
            break
    if(ans==-1):
        print("NO")
    else:
        print("YES")
        print(1,end=" ")
        print(i)
        
    
        