t = int(input())

def check(mas1, mas2):
    for x in mas1:
        for y in mas2:
            if x == y:
                return (1, y)
    return 'NO'

answers = []
for _ in range(t):
    noup = input()
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    answers.append(check(a, b))

for elem in answers:
    if elem == 'NO':
        print(elem)
    else:
        print('YES')
        print(elem[0], elem[1])