for _ in range(int(input())):
  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  b=list(map(int,input().split()))
  c=None
  for i in a:
    if i in b:
      c=i
      break
  if c==None:
    print('NO')
  else :
    print('YES')
    print(1,c)