# cook your dish here
t=int(input())
while(t!=0):
    flag=0
    n,m=map(int,input().split())
    ln=list(map(int,input().split()))
    lm=list(map(int,input().split()))
    for i in ln:
        for j in lm:
            if(i==j):
                print("YES")
                print(1,i)
                flag=1
                break
        if(flag==1):
            break
    if(flag==0):
        print("NO")
    t=t-1