T = int(input())
for t in range(T):
    n, m = [int(i) for i in input().split()]
    A = set([int(i) for i in input().split()])
    B = set([int(i) for i in input().split()])
    C = list(A & B)
    if len(C) > 0:
        print("YES")
        print(*[1, C[0]])
    else:
        print("NO")