def go(a,b):
    for i in set(a):
        if i in b:
            print("YES")
            print(1,i)
            return
    print("NO")

t=int(input())
for _ in range(t):
    n,m= map(int,input().split(" "))

    a= list(map(int,input().split(" ")))
    b= list(map(int,input().split(" ")))
    go(a,b)

