#include <bits/stdc++.h>
using namespace std;
long double eps = 1e-12;
const long long INF = 0x3f3f3f3f;
const long long inf = INF;
long long modulo = 998244353;
vector<pair<int, int> > all;
int arr[500500];
stack<int> mn;
set<int> unseen;
bool J(pair<int, int>& a, pair<int, int>& b) {
  if (a.second != b.second) return a.second < b.second;
  return (a.second - a.first) < (b.second - b.first);
}
void deal() {
  int t;
  cin >> t;
  for (long long l = 0; l < t; l++) {
    int n;
    cin >> n;
    all.clear();
    unseen.clear();
    while (mn.size()) mn.pop();
    bool bad = 0;
    for (long long i = 0; i < n; i++) {
      unseen.insert(i);
      int ed;
      cin >> ed;
      ed -= 2;
      if (ed < 0) ed = i;
      all.push_back(make_pair(i, ed));
      if (mn.size() && ed > mn.top()) bad = 1;
      mn.push(ed);
      while (mn.size() && mn.top() == i) mn.pop();
    }
    unseen.insert(n);
    if (bad) {
      cout << -1 << '\n';
      continue;
    }
    int cnt = 0;
    sort(all.begin(), all.end(), J);
    for (long long i = 0; i < all.size(); i++) {
      set<int>::iterator sv, fr = unseen.lower_bound(all[i].first);
      if (*fr > all[i].second) continue;
      sv = fr;
      int cont = 0;
      while (*fr <= all[i].second) ++cont, ++fr;
      fr = sv;
      int add_ = cont;
      while (*fr <= all[i].second) {
        sv = fr;
        ++sv;
        arr[*fr] = cnt + cont;
        --cont;
        unseen.erase(fr);
        fr = sv;
      }
      cnt += add_;
    }
    for (long long i = 0; i < n; i++) cout << arr[i] << ' ';
    cout << '\n';
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  deal();
}
