// AC

#include <iostream>
#include <vector>

using namespace std;

int n, k;

vector<int> create_equal(int n, int k) {
    vector<vector<int>> groups(k+1);
    int r = n/k;
    int u = n;
    while (r > 3) {
        for (int i = 1; i <= k; i++) groups[i].push_back(u--);
        for (int i = k; i >= 1; i--) groups[i].push_back(u--);
        r -= 2;
    }
    for (int i = 0; i < k; i++) groups[i+1].push_back(u-i);
    for (int i = 0; i < k; i++) groups[i+1].push_back(2*i%k+1);
    for (int i = 0; i < k; i++) groups[i+1].push_back(1L*u*(u+1)/2/k-(u-i)-(2*i%k+1));
    vector<int> ans(n);
    for (int c = 1; c <= k; c++) {
        for (auto p : groups[c]) {
            ans[p-1] = c-1;
        }
    }
    return ans;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> k;
        vector<int> count(k+1);
        for (int i = 1; i <= n; i++) {
            int c;
            cin >> c;
            count[c]++;
        }
        vector<int> left, right;
        vector<int> one;
        vector<int> three;
        for (int c = 1; c <= k; c++) {
            if (count[c]%2 == 0) {
                for (int i = 1; i <= count[c]/2; i++) {
                    left.push_back(c);
                    right.push_back(c);
                }
            } else if (count[c] == 1) {
                one.push_back(c);
            } else {
                while (count[c] > 3) {
                    left.push_back(c);
                    right.push_back(c);
                    count[c] -= 2;
                }
                three.push_back(c);
            }
        }

        if (one.size() == 1 && three.size() && three.size() % 2 == 0 && !left.size()) {
            vector<int> order;
            int r = (n-1)/3+1;
            for (int i = 0; i < r-1; i++) order.push_back((2*(i+1))%r);
            for (int i = 1; i < r; i += 2) order.push_back(i);
            order.push_back(0);
            for (int i = 2; i < r; i += 2) order.push_back(i);
            for (int i = r-1; i >= 1; i--) order.push_back(i);

            vector<int> labels;
            labels.push_back(one[0]);
            for (auto c : three) labels.push_back(c);
            for (int i = 0; i < n; i++) order[i] = labels[order[i]];

            cout << "YES\n";
            for (auto c : order) cout << c << " ";
            cout << "\n";
            continue;
        }

        bool fail = false;
        if (one.size() > 1) fail = true;
        if (one.size() && three.size() && left.size() == 0) fail = true;
        if (fail) {
            cout << "NO\n";
            continue;
        }

        int addm = 0, addl = 0;
        if (one.size() && three.size()) {
            addm = one[0];
            addl = left.back();
            three.push_back(one[0]);
            one.clear();
            left.pop_back();
            right.pop_back();
        }

        if (three.size() > 0 && three.size()%2 == 0) fail = true;
        if (fail) {
            cout << "NO\n";
            continue;
        }

        vector<int> middle;
        if (one.size()) {
            middle = {one[0]};
        } else if (three.size()) {
            int t = three.size();
            middle = create_equal(3*t, t);
            for (int i = 0; i < 3*t; i++) {
                middle[i] = three[middle[i]];
            }
            if (addm) {
                int newm = middle[3*t/2];
                for (int i = 0; i < 3*t; i++) {
                    if (middle[i] == addm) middle[i] = newm;
                    else if (middle[i] == newm) middle[i] = addm;
                }
                for (int i = 0; i < 3*t; i++) {
                    if (middle[i] == addm && i != 3*t/2) {
                        middle[i] = addl;
                    }
                }
            }
        }
        cout << "YES\n";
        for (int i = 0; i < left.size(); i++) cout << left[i] << " ";
        for (int i = 0; i < middle.size(); i++) cout << middle[i] << " ";
        for (int i = right.size()-1; i >= 0; i--) cout << right[i] << " ";
        cout << "\n";
    }
}
