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;
struct node {
  int p, c, id;
};
vector<node> A[310], B[310], C[310], D;
int n, mx[310], f[310][310], need[310], can[310][310], has[310], a[310], num,
    ans[310];
bool v[310], b[310];
int read() {
  int t = 0;
  char c = getchar();
  while (c != '?' && (c < '0' || c > '9')) c = getchar();
  if (c == '?') return -1;
  while (c >= '0' && c <= '9') {
    t = t * 10 + c - '0';
    c = getchar();
  }
  return t;
}
void print() {
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
int solve(int o) {
  for (int i = 1; i <= n; i++) ans[i] = 0;
  int cnt = 0, siz;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= mx[i]; j++) f[i][j] = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i] == 0) continue;
    int cir = 0;
    siz = A[i].size();
    for (int j = 0; j < siz; j++) {
      int p = A[i][j].p;
      if (f[i][p] == 0) f[i][p] = A[i][j].id;
      if (p == 0) cir++;
    }
    if (cir == 0)
      need[i] = i;
    else if (cir % i == 0)
      need[i] = 0;
    else
      need[i] = i - cir % i;
    can[i][0] = min(need[i], (int)(C[0].size()));
    for (int j = 1; j <= mx[i]; j++)
      if (f[i][j] == 0) need[i]++;
    for (int j = 1; j <= mx[i]; j++) {
      can[i][j] = can[i][j - 1];
      if (f[i][j] == 0 && C[j].size()) can[i][j]++;
    }
  }
  for (int i = 1; i <= n; i++) has[i] = B[i].size();
  for (int i = 1; i <= n; i++) b[i] = 0;
  for (int i = n; i >= 1; i--) {
    siz = C[i].size();
    int now = 0;
    for (int j = 1; j <= n; j++) {
      if (v[j] == 0 || mx[j] < i || f[j][i]) continue;
      if (now == siz) break;
      if (has[j] >= need[j]) continue;
      if (has[j] + can[j][i] <= need[j]) {
        f[j][i] = C[i][now].id;
        now++;
        need[j]--;
      }
    }
    for (int j = 1; j <= n; j++) {
      if (v[j] == 0 || mx[j] < i || f[j][i]) continue;
      if (now == siz) break;
      if (has[j] >= need[j]) continue;
      f[j][i] = C[i][now].id;
      now++;
      need[j]--;
    }
    for (int j = 1; j <= n; j++) {
      if (v[j] == 0 || mx[j] < i || f[j][i]) continue;
      if (has[j] > 0) {
        int k = B[j].size() - has[j];
        f[j][i] = B[j][k].id;
        has[j]--;
      } else if (cnt < D.size()) {
        f[j][i] = D[cnt].id;
        cnt++;
      } else
        return 0;
      need[j]--;
    }
  }
  int now = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i] == 0) continue;
    siz = A[i].size();
    num = 0;
    for (int j = 0; j < siz; j++)
      if (A[i][j].p == 0) a[++num] = A[i][j].id;
    while (now < C[0].size() && has[i] < need[i]) {
      a[++num] = C[0][now].id;
      now++;
      need[i]--;
    }
    if (has[i] + D.size() - cnt < need[i]) return 0;
    while (need[i] > 0 && has[i] > 0) {
      int k = B[i].size() - has[i];
      has[i]--;
      a[++num] = B[i][k].id;
      need[i]--;
    }
    while (need[i] > 0) {
      a[++num] = D[cnt].id;
      cnt++;
      need[i]--;
    }
    for (int j = 1; j <= num; j++) {
      if (f[i][0] == 0) f[i][0] = a[j];
      if (j % i)
        ans[a[j]] = a[j + 1];
      else
        ans[a[j]] = a[j - i + 1];
    }
    for (int j = 1; j <= mx[i]; j++) ans[f[i][j]] = f[i][j - 1];
    siz = A[i].size();
    for (int j = 0; j < siz; j++)
      if (ans[A[i][j].id] == 0) ans[A[i][j].id] = f[i][A[i][j].p - 1];
    siz = B[i].size();
    for (int j = 0; j < siz; j++)
      if (ans[B[i][j].id] == 0) ans[B[i][j].id] = f[i][0];
  }
  for (int i = 1; i <= n; i++) {
    siz = C[i].size();
    for (int j = 0; j < siz; j++)
      if (ans[C[i][j].id] == 0) ans[C[i][j].id] = f[o][i - 1];
  }
  num = 0;
  siz = C[0].size();
  for (int i = 0; i < siz; i++)
    if (ans[C[0][i].id] == 0) a[++num] = C[0][i].id;
  siz = D.size();
  for (int i = cnt; i < siz; i++) a[++num] = D[i].id;
  for (int i = 1; i < num; i++) ans[a[i]] = a[i + 1];
  ans[a[num]] = a[1];
  return 1;
}
int main() {
  scanf("%d", &n);
  int maxd = 0;
  bool bo = 0;
  for (int i = 1; i <= n; i++) {
    int p, c;
    p = read();
    c = read();
    maxd = max(maxd, p);
    node t = (node){p, c, i};
    if (c != -1 && p != -1)
      A[c].push_back(t);
    else if (c != -1 && p == -1)
      B[c].push_back(t);
    else if (c == -1 && p != -1)
      C[p].push_back(t);
    else
      D.push_back(t);
    if (c != -1) v[c] = bo = 1, mx[c] = max(mx[c], p);
  }
  if (bo == 0) v[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (v[i] == 0) continue;
    int t = mx[i];
    mx[i] = max(mx[i], maxd);
    if (solve(i)) {
      print();
      return 0;
    }
    mx[i] = t;
  }
  printf("-1\n");
  return 0;
}