t=int(input())
while(t!=0):
    n,m=list(map(int,input().split()))
    l1=[int(i) for i in input().split()]
    l2=[int(i) for i in input().split()]
    
    l1=set(l1)
    l2=set(l2)
     
    res=l1.intersection(l2)
    if(res):
        print('YES')
        print('1',res.pop())
    else:
        print("NO")
    t-=1
