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;
bool FindMatch(int i, const vector<vector<int> > &w, vector<int> &mr,
               vector<int> &mc, vector<int> &seen) {
  for (int j = 0; j < w[i].size(); j++) {
    if (w[i][j] && !seen[j]) {
      seen[j] = true;
      if (mc[j] < 0 || FindMatch(mc[j], w, mr, mc, seen)) {
        mr[i] = j;
        mc[j] = i;
        return true;
      }
    }
  }
  return false;
}
int BipartiteMatching(const vector<vector<int> > &w, vector<int> &mr,
                      vector<int> &mc) {
  mr = vector<int>(w.size(), -1);
  mc = vector<int>(w[0].size(), -1);
  int ct = 0;
  for (int i = 0; i < w.size(); i++) {
    vector<int> seen(w[0].size());
    if (FindMatch(i, w, mr, mc, seen)) ct++;
  }
  return ct;
}
int n;
int level[305];
int cyc[305];
int mxl[305];
int need[305];
int mx;
bool match(int x, int y) {
  if (x == -1 || y == -1) return true;
  return x == y;
}
vector<int> ans;
bool solveWhereMaxIs(int x) {
  vector<int> nodeCyc;
  vector<int> nodeLev;
  for (int i = 1; i <= n; i++) {
    if (i != x && mxl[i] < 0) continue;
    for (int j = 0; j < (max(1, need[i]) + i - 1) / i; j++) {
      for (int k = 0; k < i; k++) {
        nodeCyc.push_back(i);
        nodeLev.push_back(0);
      }
    }
    int lev = mxl[i];
    if (i == x) lev = max(lev, mx);
    for (int j = 1; j <= lev; j++) {
      nodeCyc.push_back(i);
      nodeLev.push_back(j);
    }
  }
  int len = nodeCyc.size();
  if (len > n) return false;
  vector<vector<int> > g(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < len; j++)
      if (match(cyc[i], nodeCyc[j]) && match(level[i], nodeLev[j]))
        g[i][j] = true;
  vector<int> L, R;
  int matches = BipartiteMatching(g, L, R);
  if (matches < len) return false;
  for (int i = 0; i < n; i++)
    if (L[i] == -1 && cyc[i] > 0 && level[i] == 0)
      for (int j = 0; j < len; j++)
        if (match(cyc[i], nodeCyc[j]) && match(level[i], nodeLev[j])) {
          if (cyc[R[j]] == -1 || level[R[j]] == -1) {
            L[R[j]] = -1;
            R[j] = i;
            L[i] = j;
            break;
          }
        }
  ans = vector<int>(n, -1);
  int cnt = 0;
  int any[305][305];
  memset(any, -1, sizeof(any));
  for (int i = 1; i <= n; i++) {
    if (i != x && mxl[i] < 0) continue;
    for (int j = 0; j < (max(1, need[i]) + i - 1) / i; j++) {
      any[i][0] = R[cnt];
      ans[R[cnt]] = R[cnt + i - 1];
      cnt++;
      for (int k = 1; k < i; k++) {
        ans[R[cnt]] = R[cnt - 1];
        cnt++;
      }
    }
    int lev = mxl[i];
    if (i == x) lev = max(lev, mx);
    for (int j = 1; j <= lev; j++) {
      ans[R[cnt]] = R[cnt - 1];
      any[i][j] = R[cnt];
      cnt++;
    }
  }
  for (int i = 0; i < n; i++)
    if (L[i] == -1) {
      if (cyc[i] == -1 && level[i] == -1)
        ans[i] = any[x][0];
      else if (cyc[i] == -1 && level[i] == 0)
        ans[i] = i;
      else if (cyc[i] == -1)
        ans[i] = any[x][level[i] - 1];
      else if (level[i] == -1)
        ans[i] = any[cyc[i]][0];
      else
        ans[i] = any[cyc[i]][level[i] - 1];
    }
  return true;
}
bool solve() {
  memset(mxl, -1, sizeof(mxl));
  mx = 0;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    if (cyc[i] > 0) {
      mxl[cyc[i]] = max(0, max(level[i], mxl[cyc[i]]));
      if (level[i] == 0) need[cyc[i]]++;
    }
    mx = max(mx, level[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (mxl[i] < 0) continue;
    ok = true;
    if (solveWhereMaxIs(i)) return true;
  }
  if (!ok) return solveWhereMaxIs(1);
  return false;
}
char s[10];
int getNum() {
  scanf("%s", s);
  int len = strlen(s);
  if (s[0] == '?') return -1;
  int num = 0;
  for (int i = 0; i < len; i++) {
    num *= 10;
    num += s[i] - '0';
  }
  return num;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    level[i] = getNum();
    cyc[i] = getNum();
  }
  if (solve())
    for (int i = 0; i < n; i++) printf("%d ", ans[i] + 1);
  else
    printf("-1\n");
}