
















def solve(A,B,n,m):
    hashmap=dict()
    for key in A:
        hashmap[key]=1
    for key in B:
        if key in hashmap:
            print("YES")
            print(1,key)        
            break
    else:         
        print("NO")        




t=int(input())

for _ in range(t):
    n,m=map(int,input().split())
    A=[int(i) for i in input().split()]
    B=[int(i) for i in input().split()]
    solve(A,B,n,m)