t=int(input())
for _ in range(t):
   n,m= map(int, input().split())
   arr1=list(map(int,input().split()))
   arr2=list(map(int,input().split()))
   arr3=[i for i in arr1 for j in arr2 if i==j  ]
   if len(arr3)==0:
       print("NO")
   else:
       print("YES")
       print("1 "+str(arr3[0]))