Problem: Functional graph is a directed graph in which all vertices have outdegree equal to 1. Loops are allowed.

Some vertices of a functional graph lay on a cycle. From the others we can come to a cycle by making a finite number of steps along the edges (we consider only finite functional graphs in this problem).

Let's compute two values for each vertex. precyclei is the amount of edges we should pass to get to a vertex which is a part of some cycle (zero, if i itself lies on a cycle), cyclei is the length of the cycle we get to.

You are given the information about these values for some functional graph. For each vertex you know the values precyclei and cyclei, however, instead of some values there can be the question mark. It means that these values are unknown.

Build any functional graph that suits the description or determine that there is no such graph.

Input

The first line contains single integer n (1 ≤ n ≤ 300) — the number of vertices in the graph.

Each of the next n lines contain two integers — precyclei (0 ≤ precyclei ≤ n - 1) and cyclei (1 ≤ cyclei ≤ n). There could be question marks instead of some of these values.

Output

In case there is no solution, print -1.

Otherwise, print n integers. i-th of them is the number of vertex to which the edge form the i-th vertex go.

The vertices should be in the same order as they go in input data.

If there are multiple solutions, print any of them.

Examples

Input

3
0 3
0 3
? ?


Output

2 3 1 


Input

5
3 2
? ?
? ?
? ?
? ?


Output

5 3 2 2 4 


Input

8
? 3
? ?
0 2
0 2
0 3
0 3
0 3
3 3


Output

5 1 4 3 6 7 5 2 


Input

1
? ?


Output

1 


Input

6
0 3
0 3
0 3
0 3
0 3
0 3


Output

2 3 1 5 6 4 


Input

2
1 1
1 1


Output

-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
namespace MF {
const int N = 605 + 605, M = 605 * 605;
int f[N], e[2 * M], c[2 * M], fl[2 * M], nxt[2 * M], ce;
int n, s, t;
int Q[N], lvl[N];
int le[N];
void init(int _n) {
  n = _n + 2;
  s = _n;
  t = _n + 1;
  ce = 0;
  for (int i = (0); i < (n); i++) f[i] = -1;
}
void add(int a, int b, int cap) {
  nxt[ce] = f[a];
  f[a] = ce;
  e[ce] = b;
  fl[ce] = 0;
  c[ce] = cap;
  ce++;
  nxt[ce] = f[b];
  f[b] = ce;
  e[ce] = a;
  fl[ce] = 0;
  c[ce] = 0;
  ce++;
}
bool bfs() {
  for (int i = (0); i < (n); i++) lvl[i] = -1;
  int qi = 1;
  Q[0] = s;
  lvl[s] = 0;
  for (int i = (0); i < (qi); i++) {
    int x = Q[i];
    le[x] = f[x];
    for (int j = f[x]; j >= 0; j = nxt[j])
      if (c[j] - fl[j] > 0) {
        int y = e[j];
        if (lvl[y] == -1) {
          lvl[y] = lvl[x] + 1;
          Q[qi++] = y;
        }
      }
  }
  return lvl[t] != -1;
}
int aug(int cu, int cf) {
  if (cu == t) return cf;
  for (int &i = le[cu]; i >= 0; i = nxt[i])
    if (c[i] - fl[i] > 0) {
      int x = e[i];
      if (lvl[x] != lvl[cu] + 1) continue;
      int rf = aug(x, min(cf, c[i] - fl[i]));
      if (rf > 0) {
        fl[i] += rf;
        fl[i ^ 1] -= rf;
        return rf;
      }
    }
  lvl[cu] = -1;
  return 0;
}
int mf() {
  int tot = 0;
  while (bfs())
    for (int x = aug(s, 1e9); x; x = aug(s, 1e9)) tot += x;
  return tot;
}
vector<pair<int, int> > mc() {
  bfs();
  vector<pair<int, int> > res;
  for (int i = (0); i < (n); i++)
    if (lvl[i] != -1) {
      for (int j = f[i]; j >= 0; j = nxt[j])
        if (lvl[e[j]] == -1) {
          res.push_back(pair<int, int>(i, e[j]));
        }
    }
  return res;
}
}  // namespace MF
pair<int, int> rd() {
  string a, b;
  cin >> b >> a;
  int c, p;
  if (a == "?")
    c = -1;
  else
    c = atoi(a.c_str());
  if (b == "?")
    p = -1;
  else
    p = atoi(b.c_str());
  return {c, p};
}
int n;
pair<int, int> f[305];
int ind[305][305];
int ei[305][305];
int nk[305];
int asgn[305];
int unasgn[305];
int lc;
void go() {
  vector<pair<int, int> > v;
  vector<int> c0[305];
  set<int> cs;
  for (int i = (0); i < (n); i++)
    if (f[i].first != -1) cs.insert(f[i].first);
  for (int c : cs) {
    int nm0 = 0;
    int mxp = 0;
    for (int i = (0); i < (n); i++)
      if (f[i].first == c) {
        nm0 += f[i].second == 0;
        mxp = max(mxp, f[i].second);
      }
    int nc = 0;
    nc = (nm0 + c - 1) / c;
    if (nc == 0) nc = 1;
    for (int i = (0); i < (nc); i++)
      for (int j = (0); j < (c); j++) {
        ind[c][0] = int(v.size());
        if (j == 0)
          nk[int(v.size())] = int(v.size()) + c - 1;
        else
          nk[int(v.size())] = int(v.size()) - 1;
        c0[c].emplace_back(int(v.size()));
        v.emplace_back(c, 0);
        if (int(v.size()) > n) return;
      }
    for (int i = (1); i < (mxp + 1); i++) {
      ind[c][i] = int(v.size());
      nk[int(v.size())] = int(v.size()) - 1;
      v.emplace_back(c, i);
      if (int(v.size()) > n) return;
    }
  }
  MF::init(n + int(v.size()));
  for (int i = (0); i < (n); i++) {
    MF::add(MF::s, i, 1);
  }
  for (int i = (0); i < (int(v.size())); i++) {
    MF::add(n + i, MF::t, 1);
  }
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (int(v.size())); j++) {
      if ((f[i].first == -1 || f[i].first == v[j].first) &&
          (f[i].second == -1 || f[i].second == v[j].second)) {
        ei[i][j] = MF::ce;
        MF::add(i, n + j, 1);
      } else
        ei[i][j] = -1;
    }
  int r = MF::mf();
  if (r != int(v.size())) return;
  memset(asgn, -1, sizeof asgn);
  memset(unasgn, -1, sizeof unasgn);
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (int(v.size())); j++)
      if (ei[i][j] != -1 && MF::fl[ei[i][j]] == 1) {
        asgn[i] = j;
        unasgn[j] = i;
      }
  }
  int cj[305] = {};
  for (int i = (0); i < (n); i++) {
    if (f[i].first != -1 && f[i].second == 0 && asgn[i] == -1) {
      int c = f[i].first;
      while (f[unasgn[c0[c][cj[c]]]].first == c &&
             f[unasgn[c0[c][cj[c]]]].second == 0)
        cj[c]++;
      asgn[unasgn[c0[c][cj[c]]]] = -1;
      asgn[i] = c0[c][cj[c]];
      unasgn[c0[c][cj[c]]] = i;
    }
  }
  for (int i = (0); i < (n); i++) {
    if (asgn[i] != -1) {
      assert(unasgn[asgn[i]] == i);
    }
  }
  for (int i = (0); i < (n); i++) {
    if (asgn[i] != -1) {
      printf("%d ", unasgn[nk[asgn[i]]] + 1);
    } else if (f[i].first != -1 && f[i].second != -1) {
      printf("%d ", unasgn[ind[f[i].first][f[i].second - 1]] + 1);
    } else if (f[i].first == -1 && f[i].second != -1) {
      if (f[i].second == 0)
        printf("%d ", i + 1);
      else
        printf("%d ", unasgn[ind[lc][f[i].second - 1]] + 1);
    } else if (f[i].second == -1 && f[i].first != -1) {
      printf("%d ", unasgn[ind[f[i].first][0]] + 1);
    } else {
      printf("%d ", i + 1);
    }
  }
  printf("\n");
  exit(0);
}
int main() {
  scanf("%d", &n);
  int mxun = -1;
  for (int i = (0); i < (n); i++) {
    f[i] = rd();
    if (f[i].first == -1 && f[i].second != -1 &&
        (mxun == -1 || f[i].second > f[mxun].second))
      mxun = i;
  }
  if (mxun == -1)
    go();
  else {
    for (f[mxun].first = 1; f[mxun].first <= n; f[mxun].first++) {
      lc = f[mxun].first;
      go();
    }
  }
  printf("-1\n");
}