for _ in range(int(input())):
    n, m = map(int, input().split())
    a = [*map(int, input().split())]
    b = [*map(int, input().split())]

    c = set(a).intersection(set(b))

    if len(c) == 0:
        print('NO')
    else:
        print('YES')
        print(1, [*c][0])