#include <bits/stdc++.h>
#define LSOne(s) ((S) & (-S))
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
void solve(){
ll n,i,a,k,t,m,actual,ini,fin;
cin>>n;
vector<pair<ll,ll> > datos(n);
for(i=0;i<n;i++){
cin>>datos[i].first;
datos[i].second=i;
}
ll conteo=0;
vector<ll> elementos(n);
sort(datos.begin(),datos.end());
conteo=0;
actual=n;
ini=0;
fin=n;
bool posible=1;
ll aux;
ll positivos=0;
while(ini<fin && actual>0){
if(conteo<datos[ini].first && ini<fin){
while(conteo<datos[ini].first && ini<fin){
aux = fin;
while(fin>0 && datos[fin-1].first==datos[fin-2].first){
elementos[datos[fin-1].second]=actual;
fin--;
conteo++;
positivos++;
}
if(fin-ini+positivos!=datos[fin-1].first){
posible=0;
}
elementos[datos[fin-1].second]=actual;
fin--;
conteo++;
positivos++;
}
actual--;
}
if(ini>=fin)continue;
if(actual==0){
posible=0;
continue;
}
if(conteo==datos[ini].first){
while(datos[ini].first==datos[ini+1].first && ini<fin-1){
elementos[datos[ini].second]=-actual;
ini++;
}
elementos[datos[ini].second]=-actual;
ini++;
}else{
posible=0;
}
actual--;
}
if(posible){
cout<<"YES\n";
for(i=0;i<n;i++){
cout<<elementos[i]<<" ";
}
cout<<"\n";
}else{
cout<<"NO\n";
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll t;
cin>>t;
while(t--)solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgTFNPbmUocykgKChTKSAmICgtUykpCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CnR5cGVkZWYgdmVjdG9yPGludD4gdmk7CnR5cGVkZWYgdmVjdG9yPGxsPiB2bGw7CnR5cGVkZWYgdmVjdG9yPGJvb2w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ICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGZpbi1pbmkrcG9zaXRpdm9zIT1kYXRvc1tmaW4tMV0uZmlyc3QpewogICAgICAgICAgICAgICAgICAgIHBvc2libGU9MDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsZW1lbnRvc1tkYXRvc1tmaW4tMV0uc2Vjb25kXT1hY3R1YWw7CiAgICAgICAgICAgICAgICBmaW4tLTsKICAgICAgICAgICAgICAgIGNvbnRlbysrOwogICAgICAgICAgICAgICAgcG9zaXRpdm9zKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYWN0dWFsLS07CiAgICAgICAgfQogICAgICAgIGlmKGluaT49ZmluKWNvbnRpbnVlOwogICAgICAgIGlmKGFjdHVhbD09MCl7CiAgICAgICAgICAgIHBvc2libGU9MDsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGlmKGNvbnRlbz09ZGF0b3NbaW5pXS5maXJzdCl7CiAgICAgICAgICAgIHdoaWxlKGRhdG9zW2luaV0uZmlyc3Q9PWRhdG9zW2luaSsxXS5maXJzdCAmJiBpbmk8ZmluLTEpewogICAgICAgICAgICAgICAgZWxlbWVudG9zW2RhdG9zW2luaV0uc2Vjb25kXT0tYWN0dWFsOwogICAgICAgICAgICAgICAgaW5pKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxlbWVudG9zW2RhdG9zW2luaV0uc2Vjb25kXT0tYWN0dWFsOwogICAgICAgICAgICBpbmkrKzsKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgcG9zaWJsZT0wOwogICAgICAgIH0KICAgICAgICBhY3R1YWwtLTsKICAgIH0KICAgIGlmKHBvc2libGUpewogICAgICAgIGNvdXQ8PCJZRVNcbiI7CiAgICAgICAgZm9yKGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgY291dDw8ZWxlbWVudG9zW2ldPDwiICI7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PCJcbiI7CiAg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