tc=int(input())
while(tc>0):
    tc-=1
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a=set(a)
    b=set(b)
    c=a.intersection(b)
    if(len(c)>0):
        print("YES")
        c=list(c)
        print("1",c[0])
    else:
        print("NO")