n = int(input())
for _ in range(n):
  line = input()
  n, m = [int(x) for x in line.split()]
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  ans = 0
  n = 0
  for i in a:
    if i in b:
      ans += 1
      n = i
      break
  if ans > 0:
    print('YES')
    print(ans, i)
  else:
    print('NO')
    
