from collections import defaultdict as dd
import sys
input=sys.stdin.readline
t=int(input())
while t:
    #n=int(input())
    d=dd(int)
    n,m=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    ans=-1
    lol=0
    for i in l1:
        d[i]=1
    for i in l2:
        if(d[i]):
            ans=i
            lol=1
    if(lol==0):
       print("NO")
    else:
        print("YES")
        print(1,ans)
    t-=1
            
