n = int(input())
for i in range(n):
    a, b = [int(i) for i in input().split()]
    ai = [int(i) for i in input().split()]
    bi = [int(i) for i in input().split()]
    flag = 0
    for x in ai:
        if x in bi:
            flag = 1
            print("YES")
            print(1, x)
            break
    if flag:
        continue
    else:
        print("NO")