t=int(input())
for f in range(t):
    x=input().split()
    n=int(x[0])
    m=int(x[1])
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    flag=True
    for i in a:
        if i in b:
            print("YES")
            print("1",i)
            flag=False
            break
    if flag:
        print("NO")