#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> nxt, v, min_v;
void solve() {
  stack<int> right;
  right.push(n);
  for (int i = 0; i < n; ++i) {
    if (nxt[i] == -1) {
      v[i] = min_v[i];
      if (i + 1 < n) min_v[i + 1] = max(min_v[i + 1], v[i] + 1);
      continue;
    }
    while (i >= right.top()) right.pop();
    if (nxt[i] > right.top()) {
      printf("-1\n");
      return;
    }
    int jump = nxt[i] - i;
    v[i] = min_v[i] + jump - 1;
    if (i + 1 < n) min_v[i + 1] = max(min_v[i + 1], min_v[i]);
    if (i + jump < n) min_v[i + jump] = max(min_v[i + jump], v[i] + 1);
    right.push(nxt[i]);
  }
  for (auto it : v) printf("%d ", it);
  printf("\n");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    nxt.resize(n);
    v.resize(n);
    min_v.assign(n, 1);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &nxt[i]);
      if (nxt[i] != -1) --nxt[i];
    }
    solve();
  }
  return 0;
}
