
T = int(input())

for _ in range(T):
    m, n = input().split(' ')
    a = [int(i) for i in input().split(' ')]
    b = [int(i) for i in input().split(' ')]

    A = {}
    for i in a:
        if i not in A:
            A[i] = 0
        A[i] += 1

    found = False
    for i in b:
        if i in A:
            found = True
            print("YES")
            print(1, i)
            break

    if not found:
        print("NO")
