#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) x.begin(),x.end()
#define ll long long int
const int MAX = 1e6+7;
const int MOD = 998244353;

int main(int argc, char const *argv[]) {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int t; cin>>t;
  while(t-->0)
  {
      int n; cin>>n;
      vector<int> a(n),cost(n+100,0);
      for(int i = 0;i<n;i++) cin>>a[i];

      //set<pair<int,int> > st;
      stack<pair<int,int> > st;
      unordered_map<int,queue<int> > pq;
      for(int i = n-1;i>=0;i--)
      {
          int val = a[i];
          if(pq[val].size() == 0) pq[val].push(i);
          else
          {
          	/*
          	1
			5
			1 2 2 3 2
          	*/
            int index = -1;
            while(!st.empty() && st.top().first<=val) st.pop();
            if(!st.empty()) index = st.top().second;	
            
            if(index == -1) pq[val].push(i);
            else
            {
          	 // cout<<"index : "<<index<<" value : "<<val<<'\n' ;
              vector<int> indices;
              while(pq[val].size()>0 && pq[val].front()>index)
              {
                indices.push_back(pq[val].front());
                pq[val].pop();
              }

              for(int j = 0;j<indices.size();j++) cost[indices[j]]+=(indices.size()-1); 
              pq[val].push(i);
            }
          }
          st.push(make_pair(val,i));
        }

          for(int i=1;i<=n;i++)
          {
              int sz  = pq[i].size() - 1;
              while(pq[i].size()>0)
              {
                cost[pq[i].front()]+=sz;
                pq[i].pop();
              }
          }

          for(int i = 0;i<n;i++) cout<<cost[i]<<" ";
          cout<<endl<<'\n';

    }

  return 0;
}
