t=int(input())
for t_ in range(t):
  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  b=list(map(int,input().split()))
  flat=0
  for i in a:
    if i in b:
      print('YES')
      print(f'1 {i}')
      flat=1
      break
  if flat==0: print('NO')