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;
const int N = 330, M = 100100, oo = 1000000000;
int i, j, k, n, m, ch, x, y, nm, t, maxx, S, T, En;
int h[N << 1], c[N << 1], d[N << 1], a[N][N], mx[N], num[N], ANS[N];
struct cc {
  int x, y;
} A[N], B[N << 1];
struct dd {
  int x, y, q;
} Ans[N];
struct edge {
  int s, n, v;
} E[M];
void R(int &x) {
  x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '?') {
      x = -1;
      return;
    }
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
int max(const int &x, const int &y) {
  if (x < y) return y;
  return x;
}
int min(const int &x, const int &y) {
  if (x < y) return x;
  return y;
}
bool cmp(const dd &a, const dd &b) {
  if (a.y == b.y) return a.x < b.x;
  return a.y < b.y;
}
void E_add(int x, int y, int v) {
  E[++En].s = y;
  E[En].v = v;
  E[En].n = h[x];
  h[x] = En;
  E[++En].s = x;
  E[En].v = 0;
  E[En].n = h[y];
  h[y] = En;
}
bool bfs() {
  memset(c, 0, sizeof c);
  int i, j, k;
  i = 0;
  j = 1;
  d[1] = S;
  c[S] = 1;
  while (i < j) {
    i++;
    for (k = h[d[i]]; k; k = E[k].n)
      if (E[k].v && !c[E[k].s]) {
        c[E[k].s] = c[d[i]] + 1;
        d[++j] = E[k].s;
      }
  }
  return c[T];
}
int dfs(int x, int y) {
  if (x == T || !y) return y;
  int k, t, Y = y;
  for (k = h[x]; k; k = E[k].n)
    if (E[k].v && c[x] + 1 == c[E[k].s]) {
      t = dfs(E[k].s, min(E[k].v, y));
      E[k].v -= t;
      E[k ^ 1].v += t;
      y -= t;
      if (!y) return Y;
    }
  if (y == Y) c[x] = -1;
  return Y - y;
}
bool work() {
  S = n;
  En = 1;
  int i, j, k, sum = 0, ans = 0;
  memset(h, 0, sizeof h);
  memset(a, 0, sizeof a);
  memset(mx, -1, sizeof mx);
  memset(num, 0, sizeof num);
  for (i = 1; i <= n; i++)
    if (A[i].y != -1) {
      if (A[i].x == 0) num[A[i].y]++;
      if (A[i].y) mx[A[i].y] = max(mx[A[i].y], 0);
      mx[A[i].y] = max(mx[A[i].y], A[i].x);
    }
  for (i = 1; i <= n; i++)
    if (mx[i] > -1)
      for (j = 0; j <= mx[i]; j++) {
        a[i][j] = ++S;
        B[S].x = j;
        B[S].y = i;
      }
  S++;
  T = S + 1;
  for (i = 1; i <= n; i++) {
    if (A[i].x == 0 && A[i].y != -1)
      E_add(S, i, 0);
    else
      E_add(S, i, 1);
  }
  for (i = 1; i <= n; i++)
    if (mx[i] > -1) {
      k = i;
      while (k < num[i]) k += i;
      E_add(a[i][0], T, k - num[i]);
      sum += k - num[i] + mx[i];
      for (j = 1; j <= mx[i]; j++) E_add(a[i][j], T, 1);
    }
  if (sum > n) return 0;
  for (i = 1; i <= n; i++) {
    if (A[i].x != -1 && A[i].y != -1) {
      if (A[i].x == 0)
        E_add(i, a[A[i].y][A[i].x], 0);
      else
        E_add(i, a[A[i].y][A[i].x], 1);
      continue;
    }
    if (A[i].x == -1 && A[i].y == -1) {
      for (j = n + 1; j < S; j++) E_add(i, j, 1);
      continue;
    }
    if (A[i].x != -1) {
      for (j = 1; j <= n; j++)
        if (a[j][A[i].x]) E_add(i, a[j][A[i].x], 1);
      continue;
    }
    if (A[i].y != -1) {
      for (j = 0; j <= n; j++)
        if (a[A[i].y][j]) E_add(i, a[A[i].y][j], 1);
      continue;
    }
  }
  while (bfs()) ans += dfs(S, oo);
  if (ans != sum) return 0;
  for (i = 1; i <= n; i++) {
    Ans[i].q = i;
    if (!E[i << 1].v) {
      for (k = h[i]; k; k = E[k].n)
        if (E[k].s != S && !E[k].v) {
          Ans[i].x = B[E[k].s].x;
          Ans[i].y = B[E[k].s].y;
          break;
        }
    } else {
      for (k = h[i]; k; k = E[k].n)
        if (E[k].s != S && B[E[k].s].x) {
          Ans[i].x = B[E[k].s].x;
          Ans[i].y = B[E[k].s].y;
          break;
        }
      if (!k) {
        if (A[i].x <= 0 && A[i].y == -1) {
          Ans[i].x = 0;
          Ans[i].y = 1;
          continue;
        }
        if (A[i].x == -1 && A[i].y != -1) {
          Ans[i].x = 1;
          Ans[i].y = A[i].y;
          continue;
        }
        return 0;
      }
    }
  }
  sort(Ans + 1, Ans + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    if (Ans[i].x == 0) {
      for (j = 1; j < Ans[i].y; j++) ANS[Ans[i + j].q] = Ans[i + j - 1].q;
      ANS[Ans[i].q] = Ans[i + Ans[i].y - 1].q;
      i += Ans[i].y - 1;
    } else {
      j = i;
      while (Ans[j].x == Ans[j + 1].x && Ans[j].y == Ans[j + 1].y) j++;
      for (k = i; k <= j; k++) ANS[Ans[k].q] = Ans[i - 1].q;
      i = j;
    }
  }
  for (i = 1; i <= n; i++) printf("%d ", ANS[i]);
  puts("");
  return 1;
}
int main() {
  R(n);
  maxx = 0;
  for (i = 1; i <= n; i++) {
    R(A[i].x);
    R(A[i].y);
    if (A[i].x > maxx && A[i].y == -1) {
      maxx = A[i].x;
      t = i;
    }
  }
  if (work()) return 0;
  if (!t) return puts("-1"), 0;
  for (i = 1; i <= n; i++) {
    A[t].y = i;
    if (work()) return 0;
    A[t].y = -1;
  }
  puts("-1");
}