def go(a, b):
    for i in a:
        for j in b:
            if i == j:
                print("YES")
                print(1, i)
                return
            if i < j:
                break
    print("NO")

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

    a.sort()
    b.sort()

    go(a, b)