from sys import stdin
input = stdin.readline

for t in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    seta = set(a)
    setb = set(b)
    done = False

    if len(seta) > len(setb):
        temp = seta
        seta = setb
        setb = temp

    for n in seta:
        if n in setb:
            print("YES\n1 " + str(n))
            done = True
            break

    if not done:
        print("NO")