t=int(input())
for _ in range(t):
  n,m=map(int,input().split())
  a=set(list(map(int,input().split())))
  b=list(map(int,input().split()))
  for i in range(m):
    if b[i] in a :
      print("YES")
      print(1,str(b[i]))
      break
  else:
    print("NO")
  