for T in range(int(input())):
    n,m=[int(x) for x in input().split()]
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    if n<m: 
        n,m=m,n
        a,b=b,a
    k=[]
    for i in range(n):    
        for j in range(m):
            if a[i]==b[j]: k.append(a[i])
    if len(k)>0:
        print("YES")
        k=sorted(list(set(k))) 
        print(1,k[0])
    else: print("NO")