for _ in range(int(input())):
  n,m=map(int,input().split())
  Arr1=list(map(int,input().split()))
  Arr2=list(map(int,input().split()))
  flag=False
  for i in range(m):
    if Arr2[i] in Arr1:
       flag=True
       value=Arr2[i]
       break
  if flag:
   print("YES")
   print(1,end=" ")
   print(value)
  else:
    print("NO")
