T = int(input())
for _ in range(T):
    n, m = tuple(map(int, input().split()))
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    ok = False
    for i in range(len(x)):
        if x[i] in y:
            print('YES')
            print('1 {}'.format(x[i]))
            ok = True
            break

    if ok:
        continue
    else:
        print('NO')