def solve():
    n, m = list(map(int, input().split()))
    a = set(list(map(int, input().split())))
    b = set(list(map(int, input().split())))
    d = a.intersection(b)
    if len(d) > 0:
        print('YES')
        print('1 {}'.format(d.pop()))
    else:
        print('NO')


t = int(input())
for test in range(t):
    solve()
