test = int(input())
result = []
for t in range(test):
    arrLen = [int(length) for length in input().split()]
    a = [int(A) for A in input().split()]
    b = [int(B) for B in input().split()]
    c = -1
    for n in range(len(a)):
        if a[n] in b:
            c = a[n]
    if c == -1:
        result.append("NO")
    else:
        result.append("YES")
        result.append("1 " + str(c))
for m in range(len(result)):
    print(result[m])