#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<long long>::max();
const long long mod = 1000 * 1000 * 1000 + 7;
vector<int> a, p;
int ok;
void solve(int l, int r, int add) {
  if (l == r) return;
  vector<int> b;
  int x = l;
  while (x < r) {
    b.push_back(x);
    x = a[x];
  }
  if (x > r) {
    ok = 0;
    return;
  }
  b.push_back(r);
  for (int i = 0; i + 1 < b.size(); ++i) {
    p[b[i]] = add + r - l + i - b.size() + 1;
  }
  int y = 0;
  for (int i = 0; i + 1 < b.size(); ++i) {
    solve(b[i] + 1, b[i + 1], add + y);
    y += b[i + 1] - b[i] - 1;
  }
  return;
}
void solve() {
  int n;
  cin >> n;
  a.resize(n);
  ok = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
    if (a[i] == -2) {
      a[i] = i + 1;
    }
  }
  p.assign(n + 1, -1);
  solve(0, n, 1);
  if (!ok) {
    cout << -1 << "\n";
    return;
  }
  for (int i = 0; i < n; ++i) {
    cout << p[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
