import sys
# sys.setrecursionlimit(10**6) 
input=sys.stdin.readline
t=int(input())
for t1 in range(t):
    n,m=list(map(int,input().split(" ")))

    a=list(map(int,input().split(" ")))
    b=list(map(int,input().split(" ")))
    d={}
    for i in a:
        d[i]=1
    ans=[]
    for i in b:
        if(d.get(i,0)==1):
            ans.append(i)
            break
    if(len(ans)>0):
        print("YES")
        print(1,ans[0])
    else:
        print("NO")

