#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll _=500005;
ll N,n,s,t,a[_],ans[_],i;
map<ll,ll>b;map<ll,ll>::iterator j;
void P(){
cin>>n;b.clear();
for(i=1;i<=n;i++)cin>>a[i],b[a[i]]++;
for(s=t=0,j=b.begin();j!=b.end();j=b.upper_bound(t)){
t++;s+=j->first-t;b[j->first]--;
if(b[j->first]<1)b.erase(j);
}
for(i=n;i>=1;i--){
ans[i]=s;
j=b.lower_bound(a[i]);
if(j==b.end())s-=a[i]-t,t--;
else{
s+=j->first-a[i];b[j->first]--;
if(b[j->first]==0)b.erase(j);
}
}
for(i=1;i<=n;i++)cout<<ans[i]<<' ';
cout<<'\n';
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;while(N--)P();
}