for _ in range(int(input())):
    n,m=map(int,input().split())
    l1=set(map(int,input().split()))
    l2=set(map(int,input().split()))
    l3=list(l1.intersection(l2))
    if(len(l3)>0):
        print("YES")
        print(1,l3[0])
    else:
        print("NO")
        
    
