for _ in range(int(input())):

    n, m = map(int, input().split())

    a = set(map(int, input().split()))
    b = set(map(int, input().split()))

    c = list(a & b)

    if len(c) == 0:
        print('NO')
    else:
        print('YES')
        print(1, c[0])