T = int(input())

for _ in range(T):
    N, M = [int(x) for x in input().split(' ')]
    a = [int(x) for x in input().split(' ')]
    b = [int(x) for x in input().split(' ')]
    c = list(set(a) & set(b))
    if c:
        print(f'YES\n1 {c[0]}')
    else:
        print('NO');