# cook your dish here
for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    
    i=0
    j=0
    a.sort()
    b.sort()
    x=0
    while(i<n and j<m):
        if(a[i]==b[j]):
            x=a[i]
            break
        elif(a[i]>b[j]):
            j+=1
        else:
            i+=1
    if(x==0):
        print("NO")
    else:
        print("YES")
        print(1,x)