def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

def solve():
    l = inlt()

    a = inlt()
    b = inlt()

    for x in a:
        if(x in b):
            print("YES")
            print("1 " + str(x))
            return
    print("NO")
    return
n = inp()

for i in range(n):
    solve()
