for _ in range(int(input())):
     n,m=map(int,input().split())
     a=list(map(int,input().split()))
     b=list(map(int,input().split()));d={};k=1
     for i in a:
          d[i]=1
     for i in b:
          if i in d:
               k=0
               p=i
               break
     if k==0:
          print("YES")
          print(1,p)
     else:
          print("NO")