T = int(raw_input())
for _ in range(T):
    n, m = [int(v) for v in raw_input().split()]
    a = set([int(v) for v in raw_input().split()])
    b = [int(v) for v in raw_input().split()]
    yes = False
    for v in b:
        if v in a:
            yes = True
            break
    if yes:
        print('YES')
        print('{} {}'.format(1, v))
    else:
        print('NO') 