1
2 2
1 1
1 2
 1
1 3
3
1 2 3
 1
1 1
1000
1000
 1
2 2
2 2
2 2
 5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
 1
4 4
1 1 1 1
1 2 3 4
 1
2 3
1 1
1 2 3

YES
1 1
 YES
1 3
 YES
1 1000
 YES
1 2
 YES
1 4
YES
1 3
NO
YES
1 3
YES
1 1
 YES
1 1
 YES
1 1

def check(arr1,arr2,count=0):
    ls=[]
    for i in range(len(arr1)):
        if (arr1[i] in arr2):
            count+=1
            ls.append(arr1[i])
    if(count>0):
        ls.append(count)
    return ls
    
test=int(input())
for _ in range(test):
    n,m=map(int,input().split())
    arr1=list(map(int,input().split()))
    arr2=list(map(int,input().split()))
    count=0
    lis=[]
    if(check(arr1,arr2,count)!=lis):
        print("YES")
        lis+=(check(arr1,arr2,count))
        lis=lis[::-1]
        if(lis[0]>1):
            lis[0]=1
            lis[1]=lis[-2]
            del lis[2::]
        for i in range(len(lis)):
            print(lis[i],end=" ")
        print()
    else:
        print("NO")
    
