for i in range(int(input())):
    a,b=input().split()
    l=list(map(int,input().split()))
    l1=list(map(int,input().split()))
    l.sort()
    l1.sort()
    l2=[]
    for i in range(len(l)):
        for j in range(len(l1)):
            if(l[i]==l1[j]):
                l2.append(l[i]);
                break;
        if(l[i]==l1[j]):
            break;
    if(len(l2)>0):
        print("YES")
        print("1",*l2)
    else:
        print("NO")