from collections import defaultdict
for _ in range(int(input())):
    n,m=map(int,input().split())
    d=defaultdict(int)
    arrn=list(map(int,input().split()))
    arrm=list(map(int,input().split()))
    
    for i in arrn:
        d[i]=1
    flag=0
    for i in arrm:
        if d[i]==1:
            print("YES")
            print(1,i)
            flag=1
            break
    if flag==0:
        print("NO")
        
        
    
    
