def input_values():
    return list(map(int, input().split()))

t = int(input())

for _ in range(t):
    n, m = input_values()
    array1 = input_values()
    array2 = input_values()

    intersection = list(set(array1) & set(array2))
    
    if not intersection:
        print('NO')
    else:
        result = intersection[0]
        results = [1, result]
        print('YES')
        print(' '.join(map(str, results)))