for _ in range(int(input())):
    n, m = map(int, input().split())
    array1 = input().split()
    array1.sort()
    array2 = input().split()
    array2.sort()
    result = 0
    for i in range(len(array1)):
        if array1[i] in array2:
            result = int(array1[i])
            break
    if result>0:
        print("YES")
        print("1",result)
    else:
        print('NO')