import sys, os

cases = int(sys.stdin.readline())

for x in range(cases):
    sizes = sys.stdin.readline()[:-1].split(" ")
    arrA = set(sys.stdin.readline()[:-1].split(" "))
    arrB = sys.stdin.readline()[:-1].split(" ")
    good = False
    for c in arrB:
        if c in arrA:
            print("YES")
            print("1", c)
            good = True
            break
    if not good:
        print("NO")


