def func():
    s1, s2 = map(int, input().split())
    a1 = list(map(int, input().split()))
    a2 = list(map(int, input().split()))
    for elem in a1:
        if elem in a2:
            return elem
    return 'NO'


t = int(input())
for _ in range(t):
    sol = func()
    if sol == 'NO':
        print('NO')
    else:
        print('YES')
        print('1 ', sol)
