t=int(input())
for i in range(t):
    a,b=input().split()
    c=list(map(int,input().split()))
    d=list(map(int,input().split()))
    f=[]
    for i in c:
        if i in d:
            f.append(i)
            break
    if len(f)==1:
        print("YES")
        print("1",f[0])
    else:
        print("NO")