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

t = int(input())


def subst(arr, k):
    list1 = []
    for i in range(0, k):
        for j in range(1, k + 1):
            if len(arr[i:j]) != 0:
                list1.append(arr[i:j])
    return list1


while t > 0:

    size = input()

    array1 = input()

    array2 = input()

    n = size.split()
    size1 = int(n[0])
    size2 = int(n[1])
    array1 = array1.split()
    array1 = list(map(int, array1))
    array2 = array2.split()
    array2 = list(map(int, array2))

    a = subst(array1, size1)

    b = subst(array2, size2)
    list2 = []
    for q in a:
        for w in b:
            if q == w:
                list2.append(q)
    if len(list2) > 0:
        print("YES")
        print(len(min(list2)), end=" ")
        print(min(list2))
    else:
        print("NO")

    t -= 1