t=int(input())
while(t):
    t-=1
    s=input().split()
    n=int(s[0])
    m=int(s[1])
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    d={}
    for i in b:
        if i in d:
            d[i]+=1
        else:
            d[i]=1
    count=0
    for i in a:
        if i in d:
            count+=1
            print("YES")
            print("1",end=" ")
            print(i)
            break
    if count == 0:
        print('NO')