import math as mt 
import sys,string
input=sys.stdin.readline
#print=sys.stdout.write
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
from collections import defaultdict


t=I()
for _ in range(t):
    n,m=M()
    a=set(L())
    b=set(L())
    x=a.intersection(b)
    if(len(x)==0):
        print("NO")
    else:
        print("YES")
        print(1,list(x)[0])
    
