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