#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define print(v) for(auto x:v) cout << x << " "; cout<<"\n";
using namespace std;
void mion();
signed main() {
int t; cin >> t;
while (t--) {
mion();
}
return 0;
}
struct info {
int mn,id;
info() : mn(INT_MAX), id(-1) {
}
info(int mn,int id) : mn(mn), id(id) {
}
bool operator<(const info& other) const {
return mn < other.mn || (mn == other.mn && id > other.id);
}
};
info min(const info& a, const info& b) {
return (a < b) ? a : b;
}
vector<info> seg;
vi lazy;
void init(int n) {
seg.clear();
seg.resize(4*n+1);
lazy.clear();
lazy.resize(4*n+1,0);
}
void build(int id,int low,int high,vi& arr) {
if(low == high) {
seg[id] = info(arr[low],low);
return;
}
int mid = low + (high - low)/2;
build(2*id,low,mid,arr);
build(2*id+1,mid+1,high,arr);
seg[id] = min(seg[2*id], seg[2*id+1]);
}
void push(int v) {
seg[v*2].mn += lazy[v];
lazy[v*2] += lazy[v];
seg[v*2+1].mn += lazy[v];
lazy[v*2+1] += lazy[v];
lazy[v] = 0;
}
void update(int id,int low,int high,int l,int r,int val) {
if(l > r) {
return;
}
if(low == l && high == r) {
seg[id].mn += val;
lazy[id] += val;
return;
}
push(id);
int mid = low + (high - low)/2;
update(2*id,low,mid,l,min(r,mid),val);
update(2*id+1,mid+1,high,max(l,mid+1),r,val);
seg[id] = min(seg[2*id], seg[2*id+1]);
}
info query(int id,int low,int high,int l,int r) {
if(l > r) {
return info(INT_MAX,-1);
}
if(low == l && high == r) {
return seg[id];
}
push(id);
int mid = low + (high - low)/2;
auto left = query(2*id,low,mid,l,min(r,mid));
auto right = query(2*id+1,mid+1,high,max(l,mid+1),r);
return min(left, right);
}
void mion() {
int n,i; cin >> n;
init(n);
vi v(n+1);
for(i=1;i<=n;i++) {
cin >> v[i];
}
build(1,1,n,v);
vi ans(n);
int sz = n;
while(n>0) {
i = query(1,1,n,1,n).id;
ans[i-1] = n;
update(1,1,sz,i,i,INT_MAX);
update(1,1,sz,i,sz,-1);
n--;
}
print(ans);
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