// Subtasks:
// 1: AC
// 2: AC
// 3: AC
// 4: AC
// _: WA

#include <iostream>
#include <vector>

using namespace std;

int n, k;

int count[20+1];
vector<int> masks[20+1];
int take[20+1];

bool search(int color, int mask) {
    if (color == k+1) {
        cout << "YES\n";
        vector<int> answer(n);
        for (int c = 1; c <= k; c++) {
            for (int i = 0; i < n; i++) {
                if (take[c] & (1<<i)) answer[i] = c;
            }
        }
        for (int i = 0; i < n; i++) cout << answer[i] << " ";
        cout << "\n";
        return true;
    }
    for (auto m : masks[count[color]]) {
        if ((mask&m) == 0) {
            take[color] = m;
            if (search(color+1, mask|m)) return true;
        }
    }
    return false;
}


void brute() {
    for (int i = 1; i <= n; i++) {
        int c;
        cin >> c;
        count[c]++;
    }
    for (int b = 1; b < (1<<n); b++) {
        int c = 0, s = 0;
        for (int i = 0; i < n; i++) {
            if (b&(1<<i)) {
                s += (i+1);
                c++;
            }
        }
        if ((2*s)%c == 0 && (2*s)/c == n+1) {
            masks[c].push_back(b);
        }
    }
    if (!search(1, 0)) cout << "NO\n";
}

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--) {
        for (int i = 0; i < 21; ++i) {
            count[i] = 0;
            masks[i].clear();
            take[i] = 0;
        }
        cin >> n >> k;
        if (n <= 15) {
            brute();
            continue;
        }
        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);
            }
        }
        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";
    }
}
