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 = 805, M = 500005, inf = 1000000007;
using namespace std;
int n, a[N], b[N], e, ter[M], nxt[M], lnk[N], w[M], rec[M], dis[N], opt[N],
    A[N], B[N], cur[N];
char ch[50];
int bel[N], sz[N], h[N], g[N], val[N][N], co, cnt, s, t, m, d[N], ans[N];
int read() {
  int ret = 0;
  int len = strlen(ch);
  for (int i = 0; i <= len - 1; ++i) ret = ret * 10 + ch[i] - '0';
  return ret;
}
void add(int x, int y, int z) {
  ter[++e] = y, nxt[e] = lnk[x], lnk[x] = e, w[e] = z, rec[e] = e + 1;
  ter[++e] = x, nxt[e] = lnk[y], lnk[y] = e, w[e] = 0, rec[e] = e - 1;
}
bool bfs() {
  for (int i = s; i <= t; ++i) dis[i] = 0;
  int he = 0, ta = 1;
  opt[1] = s, dis[s] = 1;
  for (; he != ta;) {
    ++he;
    int u = opt[he];
    for (int i = lnk[u]; i; i = nxt[i])
      if (w[i] && !dis[ter[i]]) {
        dis[ter[i]] = dis[u] + 1;
        opt[++ta] = ter[i];
      }
  }
  return dis[t];
}
int dfs(int p, int sum) {
  if (p == t) return sum;
  int res = 0;
  for (int i = cur[p]; i; i = nxt[i])
    if (w[i] && dis[ter[i]] == dis[p] + 1) {
      int tmp = dfs(ter[i], min(sum - res, w[i]));
      w[i] -= tmp, w[rec[i]] += tmp, res += tmp;
      if (w[i]) cur[p] = i;
      if (res == sum) return res;
    }
  if (!res) dis[p] = -1;
  return res;
}
int dinic() {
  int ret = 0;
  for (; bfs();) {
    for (int i = s; i <= t; ++i) cur[i] = lnk[i];
    ret += dfs(s, inf);
  }
  return ret;
}
bool check() {
  for (int i = 1; i <= e; ++i) nxt[i] = 0;
  for (int i = s; i <= t; ++i) lnk[i] = 0;
  e = 0;
  cnt = s = m = 0;
  for (int i = 1; i <= n; ++i)
    if (h[i] || g[i] >= 0) {
      int x = i - sz[h[i]];
      if (x) {
        ++m;
        A[m] = 0, B[m] = i;
        add(s, m, x);
        cnt += x;
      }
      for (int j = 1; j <= g[i]; ++j)
        if (!val[i][j]) {
          ++m;
          A[m] = j, B[m] = i;
          add(s, m, 1);
          cnt += 1;
        }
    }
  int tot = 0;
  t = m + n + 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] < 0 || b[i] < 0) {
      for (int j = 1; j <= m; ++j)
        if ((a[i] == A[j] || a[i] == -1) && (b[i] == B[j] || b[i] == -1))
          add(j, m + i, 1);
      add(m + i, t, 1);
      ++tot;
    }
  if (cnt > tot) return false;
  int ret = dinic();
  if (ret < cnt) return false;
  return true;
}
bool solve() {
  bool flg = true;
  for (int i = 1; i <= n; ++i) g[i] = -1;
  for (int i = 1; i <= n; ++i)
    if (!b[i]) return false;
  for (int i = 1; i <= n; ++i)
    if (b[i] != -1) flg = false;
  if (flg) {
    flg = false;
    for (int i = 1; i <= n; ++i)
      if (a[i] == 0) {
        a[i] = 0, b[i] = 1;
        flg = true;
        break;
      }
    if (!flg) {
      for (int i = 1; i <= n; ++i)
        if (a[i] == -1) {
          a[i] = 0, b[i] = 1;
          flg = true;
          break;
        }
    }
    if (!flg) return false;
  }
  for (int i = 1; i <= n; ++i)
    if (a[i] > n || b[i] > n) return false;
  for (int i = 1; i <= n; ++i) h[i] = 0;
  for (int i = 1; i <= n; ++i)
    if (b[i] > 0 && !a[i]) {
      int u = i;
      if (h[b[i]] && sz[h[b[i]]] < b[i]) u = h[b[i]];
      ++sz[u];
      if (u == i) h[b[i]] = i;
      bel[i] = u;
    }
  for (int i = 1; i <= n; ++i)
    if (a[i] >= 0 && b[i] >= 0)
      g[b[i]] = max(g[b[i]], a[i]), val[b[i]][a[i]] = i;
  for (int i = 1; i <= n; ++i)
    if (b[i] >= 0) g[b[i]] = max(g[b[i]], 0);
  int mx = 0, co = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] > 0 && b[i] == -1) mx = max(mx, a[i]);
  for (int i = 1; i <= n; ++i)
    if (g[i] >= mx) {
      co = i;
      if (!check()) return false;
      break;
    }
  if (!co) {
    for (int i = 1; i <= n; ++i) {
      int tmp = g[i];
      g[i] = mx;
      if (check()) {
        co = i;
        break;
      }
      g[i] = tmp;
    }
    if (!co) return false;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = lnk[m + i]; j; j = nxt[j])
      if (ter[j] <= m && w[j]) {
        a[i] = A[ter[j]], b[i] = B[ter[j]];
        if (!a[i] && b[i] >= 0) {
          int u = i;
          if (h[b[i]] && sz[h[b[i]]] < b[i]) u = h[b[i]];
          ++sz[u];
          if (u == i) h[b[i]] = i;
          bel[i] = u;
        }
      }
  for (int i = 1; i <= n; ++i)
    if (a[i] < 0 || b[i] < 0) {
      if (a[i] < 0 && b[i] < 0)
        a[i] = 0, b[i] = 1, ans[i] = i;
      else if (a[i] < 0)
        a[i] = 1;
      else {
        if (a[i] == 0)
          b[i] = 1, ans[i] = i;
        else
          b[i] = co;
      }
    }
  for (int i = 1; i <= n; ++i) val[b[i]][a[i]] = i;
  for (int i = 1; i <= n; ++i)
    if (bel[i] == i) {
      d[0] = 0;
      for (int j = 1; j <= n; ++j)
        if (bel[j] == i) d[++d[0]] = j;
      for (int i = 2; i <= d[0]; ++i) ans[d[i]] = d[i - 1];
      ans[d[1]] = d[d[0]];
    }
  for (int i = 1; i <= n; ++i)
    if (a[i] > 0) ans[i] = val[b[i]][a[i] - 1];
  for (int i = 1; i <= n - 1; ++i) printf("%d ", ans[i]);
  printf("%d\n", ans[n]);
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch);
    if (ch[0] == '?')
      a[i] = -1;
    else
      a[i] = read();
    scanf("%s", ch);
    if (ch[0] == '?')
      b[i] = -1;
    else
      b[i] = read();
  }
  if (!solve()) printf("-1\n");
  return 0;
}