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

p = int(input())
arr = []
for i in range(p):
    m, n = map(int, input().split())
    arr1 = [int(d) for d in input().split(" ")]
    arr2 = [int(d) for d in input().split(" ")]
    if len(arr1) >= len(arr2):
        for j in range(len(arr2)):
            if arr1.count(arr2[j]) > 0:
                arr.append(["YES", arr2[j]])
                break
            elif j == len(arr2) - 1:
                arr.append("NO")
    else:
        for j in range(len(arr1)):
            if arr2.count(arr1[j]) > 0:
                arr.append(["YES", arr1[j]])
                break
            elif j == len(arr1) - 1:
                arr.append("N0")




for j in range(len(arr)):
    if arr[j] == "NO":
        print("NO")
    else:
        print("YES")
        print(1, arr[j][1])
