t=int(input())
while t>0:
    f=0
    a,b=input().split(" ");
    a=int(a)
    b=int(b)
    arr=input().split()
    brr=input().split()
    if len(arr)<=len(brr):
        for i in arr:
            if i in brr:
                f=1
                break
    else:
        for i in brr:
            if i in arr:
                f = 1
                break
    if f==1:
        print("YES")
        print("1",i)
    else:
        print("NO")
    t-=1