t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    flag=1
    for j in range(n):
        for k in range(m):
            if a[j]==b[k]:
                print("YES")
                print("1 ",a[j])
                flag=0
                break
        if flag==0:
            break
       
    if flag==1:
        print("NO")