inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)

t, = inp()
for _ in range(t):
    n, m = inp()
    A = set(inp())
    B = set(inp())
    C = A.intersection(B)
    if len(C) > 0:
        print('YES')
        print(1, C.pop())
    else:
        print('NO')
    