for _ in " "*int(input()):
  n,m=map(int,input().split())
  a=set(map(int,input().split()))
  b=set(map(int,input().split()))
  x=a.intersection(b)
  if len(x) ==0:
    print("NO")
  else:
    print("YES")
    print(1,list(x)[0])

