#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, d[N], l[N], to[N], ww[N], nxt[N], tt = 1, h[N], cur[N], s, t, dep[N],
                                         cnt[N], x[N], y[N], len = 0, mx[N], md,
                                         p[N];
bool vis[N], vv[1010][1010];
void adde(int u, int v, int w) {
  to[++tt] = v, ww[tt] = w, nxt[tt] = h[u], h[u] = tt;
  to[++tt] = u, ww[tt] = 0, nxt[tt] = h[v], h[v] = tt;
}
bool bfs() {
  memset(dep, 0, 4 * (t + 1));
  queue<int> q;
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = h[u], v; v = to[i], i; i = nxt[i])
      if (!dep[v] && ww[i]) {
        dep[v] = dep[u] + 1;
        q.push(v);
        if (v == t) return 1;
      }
  }
  return 0;
}
int dfs(int u, int flow) {
  if (u == t) return flow;
  int ret = 0;
  for (int &i = cur[u], v; v = to[i], i; i = nxt[i])
    if (dep[v] == dep[u] + 1 && ww[i]) {
      int d = dfs(v, min(flow, ww[i]));
      ww[i] -= d, ww[i ^ 1] += d, ret += d, flow -= d;
      if (!flow) return ret;
    }
  dep[u] = 0;
  return ret;
}
int dinic() {
  int ret = 0;
  while (bfs()) {
    memcpy(cur, h, 4 * (t + 1));
    ret += dfs(s, 1e9);
  }
  return ret;
}
int get() {
  string s;
  cin >> s;
  if (s == "?") return -1;
  return atoi(s.c_str());
}
vector<int> vec[N];
bool cmp(int x, int y) { return d[x] < d[y]; }
void build_cyc(vector<int> a) {
  for (int i = 0; i < int(a.size()) - 1; i++) p[a[i]] = a[i + 1];
  p[a.back()] = a[0];
}
void build() {
  for (int i = 1; i <= n; i++) vec[l[i]].push_back(i);
  for (int i = 1; i <= n; i++)
    if (!vec[i].empty()) {
      sort(vec[i].begin(), vec[i].end(), cmp);
      int lst;
      while (!vec[i].empty() && d[vec[i][0]] == 0) {
        vector<int> cyc;
        for (int j = 1; j <= i; j++)
          cyc.push_back(lst = vec[i][0]), vec[i].erase(vec[i].begin());
        build_cyc(cyc);
      }
      for (int j = 0; j < int(vec[i].size()); j++) {
        if (j && d[vec[i][j]] != d[vec[i][j - 1]]) lst = vec[i][j - 1];
        p[vec[i][j]] = lst;
      }
    }
  for (int i = 1; i <= n; i++) cout << p[i] << ' ';
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    d[i] = get(), l[i] = get();
    if (~l[i]) {
      vis[l[i]] = 1;
      if (d[i] == 0) ++cnt[l[i]];
      if (~d[i]) vv[d[i]][l[i]] = 1;
      mx[l[i]] = max(mx[l[i]], d[i]);
    }
    if (!~l[i]) md = max(md, d[i]);
  }
  for (int a = 1; a <= n; a++) {
    bool _vis = vis[a], _vv = vv[md][a];
    int _mx = mx[a];
    if (md) vis[a] = 1, mx[a] = max(mx[a], md), vv[md][a] = 1;
    len = 0;
    for (int i = 1; i <= n; i++)
      if (vis[i]) {
        int need = max(1, (cnt[i] - 1) / i + 1) * i;
        for (int j = 1; j <= need - cnt[i]; j++) x[++len] = 0, y[len] = i;
        for (int j = 1; j <= mx[i]; j++)
          if (!vv[j][i]) x[++len] = j, y[len] = i;
      }
    bool fl = 0;
    t = n + len + 1;
    tt = 1;
    memset(h, 0, 4 * (t + 1));
    for (int i = 1; i <= n; i++) {
      if (~l[i] && ~d[i]) continue;
      if (md && d[i] == md && !fl) {
        fl = 1;
        continue;
      }
      adde(s, i, 1);
      for (int j = 1; j <= len; j++)
        if ((d[i] == -1 || d[i] == x[j]) && (l[i] == -1 || l[i] == y[j]))
          adde(i, j + n, 1);
    }
    for (int i = 1; i <= len; i++) adde(i + n, t, 1);
    if (dinic() == len) {
      for (int u = 1; u <= n; u++)
        for (int i = h[u], v; v = to[i], i; i = nxt[i])
          if (!ww[i] && n + 1 <= v && v <= n + len) {
            d[u] = x[v - n];
            l[u] = y[v - n];
            break;
          }
      bool fl = 0;
      for (int i = 1; i <= n; i++) {
        if (~l[i] && ~d[i]) continue;
        if (md && d[i] == md && !fl) {
          fl = 1;
          l[i] = a;
        } else {
          if (!~l[i] && !~d[i])
            l[i] = 1, d[i] = 0;
          else if (~l[i])
            d[i] = 1;
          else if (d[i] == 0)
            l[i] = 1;
          else
            l[i] = a;
        }
      }
      build();
      return 0;
    }
    vis[a] = _vis, mx[a] = _mx, vv[md][a] = _vv;
  }
  cout << "-1";
  return 0;
}
