numberOfTc=int(input())
for ctr in range(1,numberOfTc+1):
  m,n=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  b=sorted(list(map(int,input().split())))
  for i in a:
    if i in b:
      print("YES",1,i)
      break
  else:
    print("NO")
