t = int(input())
for _ in range(t):
    m, n = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    set_a = set(a)
    for i in range(n):
        if b[i] in set_a:
            print("YES")
            print(1, b[i])
            break
    else:
        print("NO")