for _ in range(int(input())):
    #n = int(input())
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    t = True
    for i in range(len(A)):
        for j in range(len(B)):
            if A[i] == B[j]:
                t = False
                break
        if t == False:
            break
    if t:
        print('NO')
    else:
        print('YES')
        print(1, A[i])