def solve():
    t = input().split()
    n, m = int(t[0]), int(t[1])
    a = set()
    t = input().split()
    for item in t:
        a1 = int(item)
        a.add(a1)
    t2 = input().split()
    for item in t2:
        b1 = int(item)
        if b1 in a:
            print("YES")
            print(1, b1)
            return
    print("NO")

t = int(input())
while t > 0:
    solve()
    t -= 1
