for i in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    x = [0 for k in range(1000)]
    for c in a:
        x[c - 1] += 1

    my = 0

    for c in b:
        if x[c - 1] > 0:
            my = c
            break

    if my > 0:
        print('YES')
        print(1, my)
    else:
        print('NO')