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>
const int N = 300 + 10;
int nextInt() {
  char ch;
  while (ch = getchar(), !isdigit(ch) && ch != '?') {
  }
  if (ch == '?') return -1;
  int res = ch - '0';
  while (isdigit(ch = getchar())) res = 10 * res + ch - '0';
  return res;
}
struct Info {
  int x, y;
  Info() {}
  Info(int _x, int _y) : x(_x), y(_y) {}
} l[N], r[N];
inline bool check(int a, int b) { return a == b || a == -1 || b == -1; }
int n, m;
int ans[N];
int match[N];
bool flag[N], adj[N][N];
bool mx[N], my[N];
bool dfs(int a) {
  for (int b = 1; b <= m; ++b) {
    if (!adj[a][b] || flag[b] || my[b]) continue;
    flag[b] = true;
    if (!match[b] || dfs(match[b])) return match[b] = a, true;
  }
  return false;
}
int a[N], b[N];
bool solve(int p, int q) {
  m = 0;
  for (int i = 1; i <= n; ++i) {
    int u = a[i], v = b[i];
    if (i == p && q != -1) u = std::max(u, i), v = std::max(v, q);
    for (int j = u; j--;) {
      r[++m] = Info(0, i);
      if (m > n) return false;
    }
    for (int j = 1; j <= v; ++j) {
      r[++m] = Info(j, i);
      if (m > n) return false;
    }
  }
  memset(mx, 0, sizeof mx);
  memset(my, 0, sizeof my);
  memset(match, 0, sizeof match);
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      adj[i][j] = (check(l[i].x, r[j].x) && check(l[i].y, r[j].y));
      if (!mx[i] && !my[j] && l[i].x == r[j].x && l[i].y == r[j].y) {
        match[j] = i;
        mx[i] = my[j] = true;
        ++cnt;
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!mx[i]) memset(flag, 0, sizeof flag), cnt += dfs(i);
  return cnt == m;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) l[i].x = nextInt(), l[i].y = nextInt();
  int temp = -1;
  memset(b, -1, sizeof b);
  for (int i = 1; i <= n; ++i) {
    if (l[i].y != -1) {
      b[l[i].y] = std::max(b[l[i].y], std::max(l[i].x, 0));
      if (l[i].x == 0) ++a[l[i].y];
    } else if (l[i].x > 0) {
      temp = std::max(temp, l[i].x);
    }
  }
  for (int i = 1; i <= n; ++i)
    if (b[i] != -1) a[i] = std::max((a[i] + i - 1) / i, 1) * i;
  for (int i = 1; i <= n; ++i) {
    if (solve(i, temp)) {
      for (int j = 1; j <= n; ++j)
        if (l[j].y == -1 && l[j].x > 0) l[j].y = i;
      goto success;
    }
  }
  puts("-1");
  return 0;
success:
  for (int i = 1; i <= m; ++i) l[match[i]] = r[i];
  for (int i = 1; i <= n; ++i)
    if (l[i].x <= 0 && l[i].y == -1)
      l[i] = Info(0, 1);
    else if (l[i].x == -1)
      l[i].x = 1;
  for (int i = 1; i <= n; ++i) {
    if (ans[i]) continue;
    if (l[i].x == 0) {
      std::vector<int> cur;
      cur.push_back(i);
      for (int j = i + 1; j <= n && cur.size() < l[i].y; ++j)
        if (l[j].x == 0 && l[j].y == l[i].y) cur.push_back(j);
      for (int j = 0; j < cur.size(); ++j)
        ans[cur[j]] = cur[(j + 1) % cur.size()];
      assert(cur.size() == l[i].y);
    } else {
      for (int j = 1; j <= n; ++j)
        if (l[i].y == l[j].y && l[i].x == l[j].x + 1) ans[i] = j;
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}