#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 500;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const long double eps = 0.00001;
const int P = 1336;
const int inf = 1e9;
vector<int> g[N];
int z[N], r[N], vh[N], a[N], u[N], ans[N], used[N];
int n;
bool fl = 0;
void DFS(int v) {
  used[v] = 1;
  for (auto to : g[v]) {
    if (used[to] == 1) {
      fl = 1;
      return;
    }
    if (used[to] == 0) DFS(to);
  }
  used[v] = 2;
}
void dfs(int v) {
  u[v] = 1;
  ans[v] = 0;
  for (auto to : g[v]) {
    if (u[to] == 0) dfs(to);
    ans[v] = min(ans[v], ans[to] - 1);
  }
}
void solve() {
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 0; i <= n + 1; i++) {
    g[i].clear();
    u[i] = 0;
    r[i] = 0;
    used[i] = 0;
    vh[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == -1) continue;
    a[i]--;
    g[i].push_back(a[i]);
    vh[a[i]]++;
    v.push_back({i, 1});
    v.push_back({a[i], 0});
  }
  sort(v.begin(), v.end());
  int uk = 0;
  vector<int> c;
  for (int i = 0; i < n; i++) {
    vector<int> add;
    while (uk < v.size() && v[uk].first == i) {
      if (v[uk].second == 1)
        add.push_back(i);
      else
        c.pop_back();
      uk++;
    }
    if (c.size() == 0)
      z[i] = -1;
    else
      z[i] = c.back();
    for (auto to : add) {
      c.push_back(to);
    }
    if (z[i] == -1) continue;
    g[i].push_back(z[i]);
    vh[z[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (vh[i] == 0) {
      vh[i] = 1;
      g[n + 1].push_back(i);
    }
  }
  fl = 0;
  DFS(n + 1);
  if (fl == 1) {
    cout << -1 << '\n';
    return;
  }
  dfs(n + 1);
  int mi = inf;
  for (int i = 0; i < n; i++) {
    mi = min(mi, ans[i]);
  }
  int add = 0;
  if (mi <= 0) add += abs(mi) + 1;
  for (int i = 0; i < n; i++) {
    ans[i] += add;
  }
  vector<pair<int, int> > ve;
  for (int i = 0; i < n; i++) {
    ve.push_back({ans[i], i});
  }
  sort(ve.begin(), ve.end());
  mi = 1;
  for (auto to : ve) {
    ans[to.second] = mi;
    mi++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
