t=int(input())
for i in range(t):
    m,n=map(int,input().split())
    x=[i for i in input().split()]
    z=[i for i in input().split()]
    a=set(x)
    b=set(z)
    d=list(a&b)
    if d:
        print("YES")
        print("1"," ",d[0])
    else:
        print("NO")