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

n=int(input())
for i in range(n):
    list1=[]
    m,n=[int(x) for x in input().split()]
    x=[int(x) for x in input().split()]
    y=[int(y) for y in input().split()]
    for ele1 in x:
        for ele2 in y:
            if(ele1==ele2):
                list1.append(ele1)
    if(len(list1)!=0):
        print("YES")
        if(len(list1)>1):
            try:
                if(x==y):
                    list1.remove(1)
            except Exception:
                pass
        if(x==y):
            print(1,min(list1))
        else:
            str1 = ' '.join(map(str, list1))
            print(len(list1),str1)
    else:
        print("NO")
