#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define pb push_back
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define endl '\n'
template <class T>
using orderedSet =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void pipra(int tc) {
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1 ; i <= n ; i++)
cin >> a[i];
vector<int> spf(n + 1, 0), primes;
spf[1] = 1;
for(int i = 2 ; i <= n ; i++) {
if(spf[i] == 0) {
spf[i] = i;
primes.pb(i);
}
for(int j = 0 ; i * primes[j] <= n ; j++) {
spf[i * primes[j]] = primes[j];
if(primes[j] == spf[i])
break;
}
}
map<int, vector<int>> m;
for(int i = 1 ; i <= n ; i++) {
m[spf[i]].pb(i);
}
for(auto [e, v] : m) {
orderedSet<int> os;
for(int i = 1 ; i <= v.size() ; i++) {
os.insert(i);
}
for(auto x : v) {
auto it = os.find_by_order(a[x]);
if(it == os.end()) {
cout << "NO\n";
return;
}
a[x] = *it;
os.erase(it);
}
}
cout << "YES\n";
for(int i = 1 ; i <= n ; i++)
cout << a[i] << ' ';
cout << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
cin >> t;
for(int i = 1 ; i <= t ; i++)
pipra(i);
return 0;
}