for _ in range(int(input())):
    a,b=map(int,input().split())
    arr=list(map(int,input().split()))
    brr=list(map(int,input().split()))
    p=0
    v=[]
    for i in arr:
        if i in brr:
            z=brr.count(i)
            for j in range(z):
                v.append(i)
                p=1
    if p:
        print("YES")
        print(1,v[0])
    else:
        print("NO")