t = int(input())
for _ in range(t):
    n, m = [int(x) for x in input().strip().split()]
    a = set([int(x) for x in input().strip().split()])
    b = set([int(x) for x in input().strip().split()])
    inter = a.intersection(b)
    if len(inter) == 0:
        print('NO')
    else:
        print('YES')
        print('1 {}'.format(inter.pop()))