t=int(input())
for k in range(t):
  s=input().split()
  n,m=[int(x) for x in s]
  ap=input(). split()
  a=[ x for x in ap]
  bp=input(). split()
  b=[x for x in bp]
  c=[int(i) for i in a if i in b]
  if len(c)==0:
    print("NO")
  else:
    print("YES")
    if (len(c)>=1):
       print("1 {}".format(c[0]))
