#include <bits/stdc++.h>
using namespace std;
const int N = 310;
int n, m;
int cyc[N], prcyc[N], fa[N];
int x[N], y[N];
int cnt[N], maxlen[N];
int maxl;
int g[N][N], flg[N], ll[N], rr[N], rx[N];
vector<int> lst[N];
int dfs(int u) {
  for (int i = 1; i <= m; i++)
    if (g[u][i] && !flg[i] && !rr[i]) {
      flg[i] = 1;
      if (!rx[i] || dfs(rx[i])) return rx[i] = u, 1;
    }
  return 0;
}
bool check(int p) {
  memset(g, 0, sizeof(g));
  memset(ll, 0, sizeof(ll));
  memset(rr, 0, sizeof(rr));
  memset(rx, 0, sizeof(rx));
  m = 0;
  for (int i = 1; i <= n; i++)
    if (~maxlen[i] || i == p) {
      int c = cnt[i], pc = maxlen[i];
      if (i == p) c = max(c, i), pc = max(pc, maxl);
      for (int j = 1; j <= c; j++) {
        if (++m > n) return false;
        x[m] = i;
        y[m] = 0;
      }
      for (int j = 1; j <= pc; j++) {
        if (++m > n) return false;
        x[m] = i;
        y[m] = j;
      }
    }
  int res = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      g[i][j] = (cyc[i] == x[j] || cyc[i] == -1) &&
                (prcyc[i] == y[j] || prcyc[i] == -1);
      if (cyc[i] == x[j] && prcyc[i] == y[j] && !ll[i] && !rr[j]) {
        ll[i] = rr[j] = 1;
        rx[j] = i;
        res++;
      }
    }
  for (int i = 1; i <= n; i++)
    if (!ll[i]) memset(flg, 0, sizeof(flg)), res += dfs(i);
  return res == m;
}
void print_sol(int p) {
  for (int i = 1; i <= m; i++) cyc[rx[i]] = x[i], prcyc[rx[i]] = y[i];
  for (int i = 1; i <= n; i++)
    if (cyc[i] == -1) {
      if (prcyc[i] <= 0)
        prcyc[i] = 0, cyc[i] = 1;
      else
        cyc[i] = p;
    } else if (prcyc[i] == -1)
      prcyc[i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (cyc[i] == cyc[j] && prcyc[i] == prcyc[j] + 1) {
        fa[i] = j;
        break;
      }
  for (int i = 1; i <= n; i++)
    if (prcyc[i] == 0) {
      lst[cyc[i]].push_back(i);
      if (lst[cyc[i]].size() == cyc[i]) {
        for (int j = 0; j < cyc[i]; j++)
          fa[lst[cyc[i]][j]] = lst[cyc[i]][(j + 1) % cyc[i]];
        lst[cyc[i]].clear();
      }
    }
  for (int i = 1; i <= n; i++) printf("%d ", fa[i]);
  puts("");
}
int main() {
  scanf("%d", &n);
  memset(maxlen, 0xff, sizeof(maxlen));
  for (int i = 1; i <= n; i++) {
    char st1[5], st2[5];
    scanf("%s%s", st1, st2);
    prcyc[i] = st1[0] == '?' ? -1 : atoi(st1);
    cyc[i] = st2[0] == '?' ? -1 : atoi(st2);
    if (cyc[i] != -1) {
      maxlen[cyc[i]] = max(maxlen[cyc[i]], max(prcyc[i], 0));
      if (!prcyc[i]) cnt[cyc[i]]++;
    } else
      maxl = max(maxl, prcyc[i]);
  }
  for (int i = 1; i <= n; i++) cnt[i] = max(1, (cnt[i] + i - 1) / i) * i;
  for (int i = 1; i <= n; i++)
    if (check(i)) {
      print_sol(i);
      return 0;
    }
  puts("-1");
  return 0;
}
