t=int(input())
for _ in range(t):
    n,m=list(map(lambda x:int(x),input().split()))
    a=list(map(lambda x:int(x),input().split()))
    b=list(map(lambda x:int(x),input().split()))
    a_set=set()
    for i in a:
        a_set.add(i)
    flag=0
    for i in b:
        if i in a_set:
            print("YES")
            print(1,i)
            flag=1
            break
    if flag==0:
        print("NO")