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;
template <typename T>
bool chkmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
int readint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '?') return -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, tot, cnt1;
int a[305], b[305], v[200005], nxt[200005], h[605], mch[605], x[305],
    bs[305][305], ans[305];
bool hv[305], vis[605], vs[305][305];
pair<pair<int, int>, int> p[305];
pair<int, int> k1[100005];
void addedge(int x, int y) {
  v[++tot] = y;
  nxt[tot] = h[x];
  h[x] = tot;
  v[++tot] = x;
  nxt[tot] = h[y];
  h[y] = tot;
}
bool dfs(int u) {
  for (int p = h[u]; p; p = nxt[p]) {
    if (vis[v[p]]) continue;
    vis[v[p]] = 1;
    if (!mch[v[p]] || dfs(mch[v[p]])) {
      mch[v[p]] = u;
      return true;
    }
  }
  return false;
}
int main() {
  n = readint();
  for (int i = 1; i <= n; i++) a[i] = readint(), b[i] = readint();
  for (int i = 1; i <= n; i++)
    if (!a[i] && b[i] >= 0) x[b[i]]++;
  int bcnt = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] >= 0) hv[b[i]] = 1, bcnt++;
  if (!bcnt) hv[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (x[i] % i != 0) {
      int tmp = i - x[i] % i;
      for (int j = 1; j <= tmp; j++) k1[++cnt1] = make_pair(i, 0);
    } else if (x[i] == 0 && hv[i])
      for (int j = 1; j <= i; j++) k1[++cnt1] = make_pair(i, 0);
  }
  int amax = 0;
  for (int i = 1; i <= n; i++) chkmax(amax, a[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] > 0 && b[i] >= 0) vs[b[i]][a[i]] = 1;
  int nmax = -1, fr = 0;
  for (int i = 1; i <= n; i++) {
    int now = 0;
    for (int j = n - 1; j >= 1; j--) {
      if (vs[i][j]) {
        now = j;
        break;
      }
    }
    for (int j = 1; j <= now; j++)
      if (!vs[i][j]) k1[++cnt1] = make_pair(i, j);
  }
  int tmpcnt = cnt1;
  for (int fr = 1; fr <= n; fr++) {
    if (!hv[fr]) continue;
    int now = 0;
    for (int i = 1; i < n; i++)
      if (vs[fr][i]) now = i;
    cnt1 = tmpcnt;
    for (int i = now + 1; i < amax; i++) k1[++cnt1] = make_pair(fr, i);
    if (cnt1 > n) continue;
    memset(h, 0, sizeof(h));
    tot = 0;
    memset(mch, 0, sizeof(mch));
    for (int i = 1; i <= cnt1; i++) {
      for (int j = 1; j <= n; j++) {
        if (a[j] >= 0 && b[j] >= 0) continue;
        if ((k1[i].first == b[j] || b[j] == -1) &&
            (k1[i].second == a[j] || a[j] == -1))
          addedge(i, j + cnt1);
      }
    }
    bool fl = 1;
    for (int i = 1; i <= cnt1; i++) {
      memset(vis, 0, sizeof(vis));
      vis[i] = 1;
      if (!dfs(i)) fl = 0;
    }
    if (!fl) continue;
    for (int i = 1; i <= n; i++) {
      if (a[i] >= 0 && b[i] >= 0) continue;
      if (mch[i + cnt1])
        b[i] = k1[mch[i + cnt1]].first, a[i] = k1[mch[i + cnt1]].second;
      else {
        if (a[i] < 0 && b[i] < 0)
          a[i] = 1, b[i] = fr;
        else if (a[i] < 0)
          a[i] = 1;
        else if (b[i] < 0) {
          if (a[i] == 0)
            b[i] = 1;
          else
            b[i] = fr;
        }
      }
    }
    for (int i = 1; i <= n; i++) p[i] = make_pair(make_pair(a[i], b[i]), i);
    sort(p + 1, p + n + 1);
    int lst = 1;
    for (int i = 1; i <= n; i++) {
      if (!p[i].first.first) {
        if (bs[p[i].first.second][0])
          ans[p[i].second] = bs[p[i].first.second][0];
        bs[p[i].first.second][0] = p[i].second;
        if (i - lst + 1 == p[i].first.second)
          ans[p[lst].second] = p[i].second, lst = i + 1;
      } else {
        ans[p[i].second] = bs[p[i].first.second][p[i].first.first - 1];
        bs[p[i].first.second][p[i].first.first] = p[i].second;
      }
    }
    for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
    printf("\n");
    return 0;
  }
  printf("-1\n");
  return 0;
}