def flag(lst1, lst2, m, n):
    if m == 0 or n == 0:
        return -1
    else:
        for elem in lst1:
            if elem in lst2:
                return elem


for _ in range(int(input())):
    a1, b1 = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    result = flag(a, b, a1, b1)
    if result == -1 or result is None:
        print('NO')
    else:
        print('YES')
        print('1 {}'.format(result))
