Think Twice, Code Once
signed main() {
int T = 1;
T = read();
while (T--) {
int n = read();
vector<pii> a(n + 1);
int sum = 0;
for (int i = 1; i <= n; ++i) {
a[i].first = read(), a[i].second = i;
sum += a[i].first;
}
sort(a.begin() + 1, a.end());
int r = n;
vector<int> dp(n + 1), ans(n + 1);
ans[a[n].second] = n - 1;
for (int i = n - 1; i >= 1; --i) {
sum -= a[i + 1].first;
while (a[r].first > sum) --r;
dp[i] += r - i + dp[r];
ans[a[i].second] = i - 1 + dp[i];
}
for (int i = 1; i <= n; ++i) writesp(ans[i]);
puts("");
}
return 0;
}