t = int(input())
for _ in range(t):
  n, m = [int(s) for s in input().split(" ")]
  a = [int(s) for s in input().split(" ")]
  b = [int(s) for s in input().split(" ")]
  values = []
  for el in a:
    if el in b:
      values.append(el)
      break
  if len(values) != 0:
    print('YES')
    print(len(values), values[0])
  else:
    print('NO')