def element(a, b):
    for elem in a:
        if elem in b:
            print('YES')
            print(1, elem)
            return
    print("NO")
    
for i in range(int(input())):
    size_1, size_2 = [int(elem) for elem in input().split()]
    element([int(elem) for elem in input().split()], [int(elem) for elem in input().split()])