t=int(input())
for v in range(t):
  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  b=list(map(int,input().split()))
  dic={}
  for i in range(n):
    dic.update({a[i]:1})
  found=False
  for i in range(m):
    ans=dic.get(b[i],-1)
    if ans!=-1:
      found=True
      ele=b[i]
      break
  if found:
    print("YES")
    print(f"1 {ele}")
  else:
    print("NO")
