T=int(input())
for _ in range(T):
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    A.sort()
    flag=0
    for i in A:
        if i in B:
            flag=1
            temp=i
            break
    if flag==1:
        print("YES")
        print(1,temp)
    else:
        print("NO")
