#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e6 + 99;
const long long INF = 1e12;
const long long mod = 1e9 + 7;
vector<long long> vec;
long long N, mn, mx, cov, pos, nxt[MAX], arr[MAX], nx[MAX];
bool ok;
signed main() {
  ios_base::sync_with_stdio(false);
  long long tc;
  cin >> tc;
  while (tc--) {
    vec.clear();
    ok = true;
    cin >> N;
    for (long long A = 1; A <= N; A++) cin >> nxt[A], arr[A] = 0;
    mn = 1;
    mx = N;
    pos = 0;
    for (long long A = 1; A <= N; A++) {
      nx[A] = -1;
      if (nxt[A] == N + 1) {
        nx[A] = A;
      }
    }
    for (long long A = N; A >= 1; A--)
      if (nx[A] != -1) pos = A;
    for (long long A = N - 1; A >= 1; A--) {
      if (nx[A] == -1) nx[A] = nx[A + 1];
    }
    if (ok == false) {
      cout << -1 << "\n";
      continue;
    }
    cov = pos;
    long long cur;
    for (long long A = 1; A <= N; A++) {
      if (nxt[A] == -1) {
        if (!arr[A]) arr[A] = mn++;
      } else if (nxt[A] == N + 1) {
        if (!arr[A]) arr[A] = mx--;
      } else {
        if ((cov > A and nxt[A] > cov) or (nxt[A] > nx[A] and nx[A] != -1)) {
          ok = false;
          break;
        } else {
          vec.clear();
          cur = A;
          while (cur != -1 and cur <= N) {
            if (arr[cur]) break;
            vec.push_back(cur);
            cur = nxt[cur];
          }
          reverse(vec.begin(), vec.end());
          for (auto B : vec) arr[B] = mx--;
          cov = max(cov, nxt[A]);
        }
      }
    }
    vec.clear();
    for (long long A = N; A >= 1; A--) {
      while (!vec.empty() and arr[vec.back()] < arr[A]) vec.pop_back();
      if (!vec.empty()) {
        if (nxt[A] != vec.back() and nxt[A] != -1) {
          ok = false;
          break;
        }
      } else {
        if (nxt[A] != N + 1 and nxt[A] != -1) {
          ok = false;
          break;
        }
      }
      vec.push_back(A);
    }
    if (!ok)
      cout << -1 << "\n";
    else {
      for (long long A = 1; A <= N; A++) cout << arr[A] << " ";
      cout << "\n";
    }
  }
  return 0;
}
