def foo():
    n,m = map(int,input().split());
    
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    
    for e in a:
        if e in b:
            print("YES")
            print(1, end=" ")
            print(e)
            return
    print("NO")

t = int(input())
for _ in range(t):
    foo()