t=int(input())
while(t):
    n,m=map(int,input().split())
    a=set(map(int,input().split()))
    b=set(map(int,input().split()))
    flag=0
    for i in a:
        for j in b:
            if i==j:
                print("YES")
                print("1 ",i)
                flag=1
                break
        if flag==1:
            break
    if flag==0:
        print("NO")
    t=t-1