t = int(input())


def solve(A, B):
    B = set(B)
    for a in A:
        if a in B:
            print("YES")
            print(1, a)
            return
    print("NO")
    return


for _ in range(t):
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    solve(A, B)
