#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define repeat(x) for(int taramtam = 0;taramtam<(x);taramtam++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
template<typename S, typename T> void semax(S &a, const T &b) {if (a<b) a = b;}
template<typename S, typename T> void semin(S &a, const T &b) {if (a>b) a = b;}
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H;dbg_out(T...);}
#define debug(...) cerr << "(" #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
const int INF = 1e9+100;
const int MOD = 1e9+7;
#define int long long
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename S>
void displayvec(vector<S> a){
for (S thing:a){
cout << thing << ' ';
}
cout << '\n';
}
template <typename S>
void readvec(vector<S>& a){
for (S& thing:a){
cin>>thing;
}
}
void solve(){
int n;cin>>n;
int N=n;
vector<int> lp(N+1);
vector<int> pr;
lp[1]=1;
for (int i=2; i <= N; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.push_back(i);
}
for (int j = 0; i * pr[j] <= N; ++j) {
lp[i * pr[j]] = pr[j];
if (pr[j] == lp[i]) {
break;
}
}
}
vector<int> c(n);
readvec(c);
vector<int> a(n);
bool abr=true;
vector<vector<int>> nbg(n+1);
for(int i = 0;i<n;i++){
int group = lp[i+1];
int bt = c[i];
nbg[group].push_back(i);
}
for(auto thing:nbg){
ordered_set things;
for(int i = 1;i<=thing.size();i++){
things.insert(i);
}
for(auto thing2:thing){
int ord = c[thing2];
auto x = things.find_by_order(ord);
if (x==things.end()){
abr=false;
break;
}
a[thing2]=*x;
things.erase(*x);
}
if(!abr)break;
}
cout << (abr ? "Yes" : "No") << '\n';
if (abr){
displayvec(a);
}
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
//freopen("compin.txt", "r", stdin);
//freopen("compout.txt", "w", stdout);
int TestCase = 1;
cin >> TestCase;
while(TestCase--) solve();
}