t=int(input())
for _ in range(t):
  n,m=map(int,input().split())
  la=[int(i) for i in input().split()]
  lb=[int(i) for i in input().split()]
  cnt=None
  for i in la:
    if i in lb:
      cnt=i
      break
  if cnt==None:
    print('NO')
  else :
    print('YES')
    print(1,cnt)