#include <bits/stdc++.h>
using namespace std;
const int M = 305, N = M << 1, inf = 1 << 30;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
};
int to[N * N], nt[N * N], c[N * N], hd[N], tot = 1;
void add(int x, int y, int z) {
  ++tot, to[tot] = y, nt[tot] = hd[x], c[tot] = z, hd[x] = tot;
  ++tot, to[tot] = x, nt[tot] = hd[y], c[tot] = 0, hd[y] = tot;
}
int ps, pt, nhd[N], lv[N];
bool bfs() {
  queue<int> q;
  for (int i = 1; i <= pt; ++i) lv[i] = 0;
  lv[ps] = 1, q.push(ps);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = hd[x]; i; i = nt[i]) {
      int y = to[i];
      if (c[i] > 0 && !lv[y]) lv[y] = lv[x] + 1, q.push(y);
    }
  }
  return lv[pt];
}
int dfs(int x, int fw) {
  if (x == pt) return fw;
  int an = 0;
  for (int &i = nhd[x]; i; i = nt[i]) {
    int y = to[i];
    if (c[i] > 0 && lv[y] == lv[x] + 1) {
      int dt = dfs(y, min(fw, c[i]));
      c[i] -= dt, c[i ^ 1] += dt;
      fw -= dt, an += dt;
      if (!fw) break;
    }
  }
  return an;
}
int dinic() {
  int an = 0, dt;
  while (bfs()) {
    memcpy(nhd, hd, sizeof(int) * (pt + 1));
    while ((dt = dfs(ps, inf))) an += dt;
  }
  return an;
}
char cc[5];
int n, m, mat[N], a[N], b[N], cn[M], t[M], an[M], ff[M][M];
bool v[M], vv[M];
vector<int> cr[M];
bool ck() {
  for (int j = 1; j <= n; ++j) v[j] = 0, cn[j] = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 1; j <= n; ++j) ff[i][j] = 0;
  for (int i = 1; i <= n; ++i) {
    if ((~a[i]) && (~b[i])) {
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
      if (!a[i]) ++cn[b[i]];
    }
    if (~b[i]) v[b[i]] = 1;
  }
  m = n;
  for (int i = 1; i <= n; ++i) {
    if (!v[i]) {
      t[i] = -1;
      continue;
    }
    int nm = (i - cn[i] % i) % i;
    while (nm--) a[++m] = 0, b[m] = i;
    int w = n + 1;
    while (w && !ff[w][i]) --w;
    t[i] = w;
    while (~w) {
      if (!ff[w][i]) {
        int T = w ? 1 : i;
        while (T--) a[++m] = w, b[m] = i;
      }
      --w;
    }
  }
  if (m > n + n) return 0;
  pt = m + 1;
  memset(hd, 0, sizeof(int) * (pt + 1)), tot = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] < 0 || b[i] < 0) {
      for (int j = n + 1; j <= m; ++j)
        if ((a[i] < 0 || a[i] == a[j]) && (b[i] < 0 || b[i] == b[j]))
          add(i, j, 1);
    }
  for (int i = 1; i <= n; ++i) add(ps, i, 1);
  for (int j = n + 1; j <= m; ++j) add(j, pt, 1);
  return dinic() >= m - n;
}
int main() {
  n = rd();
  int ii = -1, mx = -1;
  bool tg = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", cc);
    if (cc[0] == '?')
      a[i] = -1;
    else {
      int len = strlen(cc);
      for (int j = 0; j < len; ++j) a[i] = a[i] * 10 + cc[j] - 48;
    }
    scanf("%s", cc);
    if (cc[0] == '?')
      b[i] = -1;
    else {
      int len = strlen(cc);
      for (int j = 0; j < len; ++j) b[i] = b[i] * 10 + cc[j] - 48;
    }
    if (a[i] >= 0 && b[i] < 0 && a[i] > mx) mx = a[i], ii = i;
    if (b[i] > 0) tg = 1, vv[b[i]] = 1;
  }
  if (~ii) {
    if (!tg)
      for (int i = 1; i <= n; ++i) vv[i] = 1;
    bool ok = 0;
    for (int i = 1; !ok && i <= n; ++i) {
      if (!vv[i]) continue;
      b[ii] = i;
      ok = ck();
    }
    if (!ok) {
      puts("-1");
      return 0;
    }
  } else {
    if (!ck()) {
      puts("-1");
      return 0;
    }
  }
  for (int j = n + 1; j <= m; ++j) {
    for (int i = hd[j]; i; i = nt[i]) {
      int x = to[i];
      if (x <= n && c[i]) {
        a[x] = a[j], b[x] = b[j];
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if ((~a[i]) && (~b[i]))
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
  for (int i = 1; i <= n; ++i) {
    t[i] = n + 1;
    while (~t[i] && !ff[t[i]][i]) --t[i];
  }
  int jj = 1;
  for (int j = 2; j <= n; ++j)
    if (t[jj] < t[j]) jj = j;
  for (int i = 1; i <= n; ++i) {
    if ((a[i] < 0) ^ (b[i] < 0)) {
      if (a[i] < 0)
        a[i] = 1;
      else
        b[i] = a[i] ? jj : 1;
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] < 0 && b[i] < 0) {
      if (a[i] < 0) a[i] = 0, b[i] = 1;
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!a[i]) {
      cr[b[i]].push_back(i);
      if ((int)cr[b[i]].size() == b[i]) {
        for (int j = 0; j < b[i] - 1; ++j) an[cr[b[i]][j]] = cr[b[i]][j + 1];
        an[cr[b[i]][b[i] - 1]] = cr[b[i]][0];
        cr[b[i]].clear();
      }
    }
  for (int i = 1; i <= n; ++i)
    if (!cr[i].empty()) {
      puts("-1");
      return 0;
    }
  for (int i = 1; i <= n; ++i)
    printf("%d ", an[i] ? an[i] : ff[a[i] - 1][b[i]]);
  return 0;
}
