for i in range(int(input())):
     n,m=map(int,input().split())
     x=list(map(int,input().split()))
     y=list(map(int,input().split()))
     mark=0
     for i in x:
         if i in y:
             print("YES")
             print(1,i)
             mark=1
             break
     if mark==0:
         print("NO")

 