for _ in range(int(input())):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    d=list(map(int,input().split()))
    k="NO"
    l=0
    for i in c:
        for j in d:
            if i==j:
                k="YES"
                l=i
                break
        if k=="YES":
            break
        
    if k=="YES":    
        print(k)
        print(1,l)
    else:
        print(k)
