def help():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split())) 
    a=set(a)
    b=set(b)
    for A in a:
        if A in b:
            print("YES")
            print(1,A)
            return
    print("NO")

t=int(input())
for T in range(t):
    help()