#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int n, m, mx, len[N], dis[N], fa[N], x[N], y[N], cnt[N], mxd[N];
int e[N][N], vis[N], l[N], r[N], mat[N];
vector<int> v[N];
char s1[5], s2[5];
inline int get_int(char *s) {
  int ret;
  sscanf(s, "%d", &ret);
  return ret;
}
int dfs(int pos) {
  for (int i = 1; i <= m; i++)
    if (e[pos][i] && !vis[i] && !r[i]) {
      vis[i] = 1;
      if (!mat[i] || dfs(mat[i])) {
        mat[i] = pos;
        return 1;
      }
    }
  return 0;
}
int check(int pos) {
  memset(e, 0, sizeof(e));
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(mat, 0, sizeof(mat));
  m = 0;
  for (int i = 1; i <= n; i++)
    if (mxd[i] != -1 || i == pos) {
      int c = cnt[i], lt = mxd[i];
      if (i == pos) c = max(c, i), lt = max(lt, mx);
      for (int j = 1; j <= c; j++)
        if (++m > n)
          return 0;
        else
          x[m] = i, y[m] = 0;
      for (int j = 1; j <= lt; j++)
        if (++m > n)
          return 0;
        else
          x[m] = i, y[m] = j;
    }
  int ret = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      e[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] && !l[i] && !r[j])
        l[i] = r[j] = 1, mat[j] = i, ++ret;
    }
  for (int i = 1; i <= n; i++)
    if (!l[i]) memset(vis, 0, sizeof(vis)), ret += dfs(i);
  return ret == m;
}
void print(int tt) {
  for (int i = 1; i <= m; i++) len[mat[i]] = x[i], dis[mat[i]] = y[i];
  for (int i = 1; i <= n; i++)
    if (len[i] == -1) {
      if (dis[i] <= 0)
        dis[i] = 0, len[i] = 1;
      else
        len[i] = tt;
    } else if (dis[i] == -1)
      dis[i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (len[i] == len[j] && dis[i] == dis[j] + 1) {
        fa[i] = j;
        break;
      }
  for (int i = 1; i <= n; i++)
    if (!dis[i]) {
      v[len[i]].push_back(i);
      if (int(v[len[i]].size()) == len[i]) {
        for (int j = 0; j < len[i]; j++)
          fa[v[len[i]][j]] = v[len[i]][(j + 1) % len[i]];
        v[len[i]].clear();
      }
    }
  for (int i = 1; i <= n; i++) cout << fa[i] << ' ';
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  memset(mxd, -1, sizeof(mxd));
  for (int i = 1; i <= n; i++) {
    cin >> s1 >> s2;
    dis[i] = s1[0] == '?' ? -1 : get_int(s1);
    len[i] = s2[0] == '?' ? -1 : get_int(s2);
    if (len[i] != -1) {
      mxd[len[i]] = max(mxd[len[i]], max(dis[i], 0));
      if (!dis[i]) ++cnt[len[i]];
    } else
      mx = max(mx, dis[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(i);
      return 0;
    }
  cout << -1 << endl;
  return 0;
}
