#include <bits/stdc++.h>
using namespace std;
int nex[500000];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> nex[i];
      if (nex[i] != -1) nex[i]--;
    }
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    auto add = [&](int a, int b) {
      adj[a].push_back(b);
      deg[b]++;
    };
    vector<int> stk;
    for (int i = 0; i < n; i++) {
      while (stk.size() && nex[stk.back()] <= i) stk.pop_back();
      if (nex[i] == -1) {
        if (stk.size()) add(i, stk.back());
      } else if (!stk.size() || nex[i] < nex[stk.back()]) {
        stk.push_back(i);
        add(i, nex[i]);
      } else {
        add(i, stk.back());
        stk.push_back(i);
      }
    }
    vector<int> ans(n);
    stk.clear();
    for (int i = 0; i < n; i++)
      if (!deg[i]) stk.push_back(i);
    int total = 0;
    while (stk.size()) {
      int u = stk.back();
      stk.pop_back();
      if (u == n) continue;
      ans[u] = ++total;
      for (int to : adj[u])
        if (--deg[to] == 0) stk.push_back(to);
    }
    if (total < n)
      cout << "-1\n";
    else {
      copy(ans.begin(), ans.end(), ostream_iterator<int>(cout, " "));
      cout << '\n';
    }
  }
}
