

    
t=int(input())
for _ in range(t):
    m,n=list(map(int,input().split(" ")))
    X=list(map(int,input().split(" ")))
    Y=list(map(int,input().split(" ")))
    ans=10000
    for i in range(m):
        for j in range(n):
            if X[i]==Y[j]:
                ans=min(ans,X[i])
            
    if  ans!=-1 and ans<=1000:
        print("YES")
        print(1,ans)
    else:
        print("NO")      
            