t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    answer = -1
    mas = [0] * 1009
    for i in range(n):
        mas[a[i]] = 1
    for i in range(m):
        if mas[b[i]] == 1:
            answer = b[i]
    if answer > 0:
        print("YES")
        print(1, answer)
    else:
        print("NO")