t=int(input())
for j in range(0,t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    aa=[0]*1001
    bb=[0]*1001
    for i in a:
        aa[i]=aa[i]+1
    for i in b:
        bb[i]=bb[i]+1
    l=0
    ans=0
    for i in a:
        if(bb[i]>0):
            ans=i
            l=1
            break
    if(l==1):
        print("YES")
        print("1 ",end="")
        print(ans)
    else:
        print("NO")
