#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "yes" : "no");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int read() {
  char ch = getchar();
  int x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar()) {
    if (ch == '?') return -1;
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x;
}
int dis[305], len[305], cnt[305], maxX[305], unMaxX;
int x[305], y[305], fa[305];
const int maxn = 305;
int edge[maxn][maxn];
int vis[maxn];
int cx[maxn], cy[maxn];
int nx, ny;
int line(int u) {
  for (int(v) = 1; (v) <= (int)(ny); (v)++) {
    if (edge[u][v] && !vis[v]) {
      vis[v] = 1;
      if (cy[v] == -1 || line(cy[v])) {
        cx[u] = v;
        cy[v] = u;
        return 1;
      }
    }
  }
  return 0;
}
bool ck(int L) {
  int cc = 0;
  for (int(len) = 1; (len) <= (int)(n); (len)++)
    if (maxX[len] != -1 || len == L) {
      int c = cnt[len], l = maxX[len];
      if (L == len) {
        l = max(l, unMaxX);
        c = max(c, len);
      }
      for (int(j) = 1; (j) <= (int)(c); (j)++) {
        if (++cc > n) return 0;
        x[cc] = len;
        y[cc] = 0;
      }
      for (int(j) = 1; (j) <= (int)(l); (j)++) {
        if (++cc > n) return 0;
        x[cc] = len;
        y[cc] = j;
      }
    }
  int ans = 0;
  memset(edge, 0, sizeof edge);
  memset(cx, 0xff, sizeof(cx));
  memset(cy, 0xff, sizeof(cy));
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (int(j) = 1; (j) <= (int)(cc); (j)++) {
      edge[i][j] =
          (len[i] == x[j] || len[i] == -1) && (dis[i] == y[j] || dis[i] == -1);
      if (len[i] == x[j] && dis[i] == y[j] && cx[i] == -1 && cy[j] == -1) {
        cx[i] = j;
        cy[j] = i;
        ++ans;
      }
    }
  nx = n;
  ny = cc;
  for (int i = 1; i <= n; i++) {
    if (cx[i] == -1) {
      memset(vis, 0, sizeof(vis));
      ans += line(i);
    }
  }
  return ans == cc;
}
void pp(int L) {
  for (int(i) = 1; (i) <= (int)(ny); (i)++) {
    int u = cy[i];
    dis[u] = y[i];
    len[u] = x[i];
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    if (len[i] == -1) {
      if (dis[i] <= 0) {
        len[i] = 1;
        dis[i] = 0;
      } else
        len[i] = L;
    } else if (dis[i] == -1) {
      dis[i] = 1;
    }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (int(j) = 1; (j) <= (int)(n); (j)++)
      if (len[i] == len[j]) {
        if (dis[i] == dis[j] + 1) {
          fa[i] = j;
          break;
        }
      }
  for (int(l) = 1; (l) <= (int)(n); (l)++) {
    vector<int> vp;
    for (int(i) = 1; (i) <= (int)(n); (i)++)
      if (dis[i] == 0 && len[i] == l) {
        vp.push_back(i);
        if (vp.size() == l) {
          for (int j = 0; j < l; j++) {
            fa[vp[j]] = vp[(j + 1) % l];
          }
          vp.clear();
        }
      }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) printf("%d ", fa[i]);
}
void fmain() {
  scanf("%d", &n);
  memset(maxX, -1, sizeof maxX);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    dis[i] = read();
    len[i] = read();
    if (len[i] != -1) {
      if (dis[i] == 0) cnt[len[i]]++;
      maxX[len[i]] = max(maxX[len[i]], max(dis[i], 0));
    } else {
      unMaxX = max(unMaxX, dis[i]);
    }
  }
  for (int len = 1; len <= n; len++) {
    for (int j = len;; j += len) {
      if (cnt[len] <= j) {
        cnt[len] = j;
        break;
      }
    }
  }
  for (int(len) = 1; (len) <= (int)(n); (len)++)
    if (ck(len)) {
      pp(len);
      return;
    }
  et();
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain();
  }
  return 0;
}
