import sys
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()))
    G=[0 for i in range(1001)]
    for i in range(n):
        G[A[i]]=1

    v=-1
    for i in range(m):
        if (G[B[i]]==1):
            v=B[i]
            break

    if (v==-1):
        print("NO")

    else:
        print("YES")
        print(1,v)
