T=int(input())
for __ in range(T):
    n,m = map(int,input().split())
    A=list(map(int,input().split()))
    B=set(map(int,input().split()))
    flag=1
    for element in A:
        if element in B:
            print("YES")
            print("1 "+str(element))
            flag=0
            break
    if flag==1:
        print("NO")
    