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 = 303;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  for (; ch != '?' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '?') {
    x = -1;
    return;
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
int n, m, res, cnt[N], dis[N], len[N], mx[N], mxd, mat[N], x[N], y[N], fa[N];
bool G[N][N], L[N], R[N], vis[N];
vector<int> tmp[N];
bool dfs(int u) {
  for (int v = 1; v <= m; ++v)
    if (G[u][v] && !vis[v] && !R[v]) {
      vis[v] = true;
      if (!mat[v] || dfs(mat[v])) {
        mat[v] = u;
        return true;
      }
    }
  return false;
}
bool check(int p) {
  memset(G, 0, sizeof G);
  memset(L, 0, sizeof L);
  memset(R, 0, sizeof R);
  memset(mat, 0, sizeof mat);
  m = res = 0;
  for (int i = 1; i <= n; ++i)
    if (~mx[i] || i == p) {
      int c = cnt[i], l = mx[i];
      if (i == p) chmax(l, mxd);
      for (int j = 1; j <= c; ++j) {
        if (++m > n) return false;
        x[m] = 0;
        y[m] = i;
      }
      for (int j = 1; j <= l; ++j) {
        if (++m > n) return false;
        x[m] = j;
        y[m] = i;
      }
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      G[i][j] = (dis[i] == x[j] || !~dis[i]) && (len[i] == y[j] || !~len[i]);
      if (dis[i] == x[j] && len[i] == y[j] && !L[i] && !R[j]) {
        L[i] = R[j] = true;
        mat[j] = i;
        ++res;
      }
    }
  for (int i = 1; i <= n; ++i)
    if (!L[i]) {
      memset(vis, 0, sizeof vis);
      res += dfs(i);
    }
  return res == m;
}
int main() {
  read(n);
  memset(mx, -1, sizeof mx);
  for (int i = 1; i <= n; ++i) {
    read(dis[i]);
    read(len[i]);
    if (~len[i]) {
      chmax(mx[len[i]], max(dis[i], 0));
      if (!dis[i]) ++cnt[len[i]];
    } else
      chmax(mxd, dis[i]);
  }
  for (int i = 1; i <= n; ++i) cnt[i] = (max(cnt[i] - 1, 0) / i + 1) * i;
  for (int p = 1; p <= n; ++p)
    if (check(p)) {
      for (int i = 1; i <= m; ++i) {
        dis[mat[i]] = x[i];
        len[mat[i]] = y[i];
      }
      for (int i = 1; i <= n; ++i)
        if (!~len[i]) {
          if (dis[i] <= 0) {
            dis[i] = 0;
            len[i] = 1;
          } else
            len[i] = p;
        } else if (!~dis[i])
          dis[i] = 1;
      for (int i = 1; i <= n; ++i)
        if (!dis[i]) {
          auto &V = tmp[len[i]];
          V.emplace_back(i);
          if (V.size() == len[i]) {
            fa[V.front()] = V.back();
            for (int i = 1; i < V.size(); ++i) fa[V[i]] = V[i - 1];
            V.resize(0);
          }
        }
      for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
          if (len[i] == len[j] && dis[i] == dis[j] + 1) {
            fa[i] = j;
            break;
          }
      for (int i = 1; i <= n; ++i) printf("%d%c", fa[i], " \n"[i == n]);
      return 0;
    }
  puts("-1");
}