tC = int(input())
for __ in range(tC):
    N, M = map(int,input().split())
    A = set(list(input().split()))
    B = set(list(input().split()))
    C = A.intersection(B)
    print('NO') if not C else print('YES\n1', C.pop())