t=int(input())
while t:
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    q=-1
    for i in a:
        if i in b:
            q=i
            break
    if q==-1:
        print("NO")
    else:
        print("YES")
        print(1,q,end=" ")
    t=t-1