t=int(input())
while t>0:
    n,m=[int(x) for x in input().split()]
    a=[int(y) for y in input().split()]
    b=[int(z) for z in input().split()]
    flag=0
    for i in range(n):
        if a[i] in b:
            flag=1
            print("YES")
            print(1,a[i])
            break

    if flag==0:
        print("NO")


            
    t-=1