for i in range(int(input())):
 n,m=map(int,input().split())
 l=[int(num) for num in input().split()]
 r=[int(num) for num in input().split()]
 l1=set(l)
 r1=set(r)
 if(l1 & r1):
  print("YES")
  print("1",list((l1&r1))[0])
 else:
  print("NO")