#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;
const int MX = 10000005;
int spf[MX], primes[MX], PIND;
map<int,vector<int>> G;
void gen_spf(int n) {
int i, j;
for (i = 1; i <= n; i += 1) spf[i] = i;
for (i = 2; i <= n; i += 2) spf[i] = 2;
for (i = 3; i <= n; i += 2) {
if (spf[i] != i) continue;
for (j = i; j <= n; j += i) {
spf[j] = min(spf[j], i);
}
}
for (i = 1; i <= n; ++i) G[spf[i]].push_back(i);
PIND = 0;
for (i = 2; i <= n; ++i) {
if (i == spf[i]) primes[PIND++] = i;
}
primes[PIND++] = 1;
}
int main() {
FAST;
gen_spf(MX-1);
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
int n, i, j, p, pi;
cin >> n;
vector<int> a(n);
for (i = 0; i < n; ++i) cin >> a[i];
vector<set<int>> at(n+1);
for (i = 0; i < n; ++i) at[a[i]].emplace(i);
bool f = 1;
vector<vector<int>> inds;
vector<int> ans(n, 0);
j = n;
while (j >= 0) {
while (!at[j].empty()) {
vector<int> curr;
auto it = at[j].begin();
curr.push_back(*it);
at[j].erase(it);
for (i = j-1; i >= 0; --i) {
auto it = at[i].lower_bound(curr.back());
if (it == at[i].end()) {
f = 0;
break;
}
curr.push_back(*it);
at[i].erase(it);
}
if (!f) break;
inds.push_back(curr);
}
if (!f) break;
--j;
}
if (f) {
sort(inds.begin(), inds.end(), [&](auto& x, auto& y) {
return ((int)x.size() < (int)y.size());
});
pi = 0;
while (!inds.empty()) {
auto& curr_inds = inds.back();
assert(pi < PIND);
p = primes[pi];
j = (int)G[p].size();
for (int x : curr_inds) {
--j;
assert(j >= 0);
ans[x] = G[p][j];
}
inds.pop_back();
++pi;
}
}
if (f) {
cout << "YES" << "\n";
for (i = 0; i < n; ++i) cout << ans[i] << " ";
cout << "\n";
} else {
cout << "NO" << "\n";
}
}
return 0;
}