t = int(input())
while t:
    n, m = map(int, input().split())
    a = [i for i in input().split()]
    b = [i for i in input().split()]
    k = -1
    for i in range(n):
        found = False
        for j in range(m):
            if a[i] == b[j]:
                k = a[i]
                found = True
                break
        if found:
            break
    if k != -1:
        print('YES')
        print(1, k)
    else:
        print('NO')
    t -= 1
