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