test_cases = int(raw_input())

for i in range(test_cases):
    size_first, size_second = raw_input().split(" ")

    first_array = raw_input().split(" ")
    second_array = raw_input().split(" ")

    aux = True

    for element in second_array:
        if element not in first_array:
            continue
        else:
            print "YES"
            print 1, element
            aux = False
            break

    if(aux == True):
        print "NO"
