t=int(input())
for _ in range(t):
    n,m=[int(s) for s in input().split()]
    a=[int(s) for s in input().split()]
    b=[int(s) for s in input().split()]
    ans=False
    for k in a:
        if k in b:
            print("YES")
            print(1,k)
            ans=True
            break
    if ans==False:
        print("NO")