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;
int n, a[310], b[310], maxd[310], cnt[310], link[310], head[310], tail[310],
    ans[310];
bool flag[310];
struct edge {
  int v;
  edge *nxt;
} pool[100000], *tp = pool, *fst[100000];
int getint() {
  char ch;
  while (!isdigit(ch = getchar()) && ch != '?')
    ;
  if (ch == '?') return -1;
  int x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return x;
}
void addedge(int u, int v) { *tp = (edge){v, fst[u]}, fst[u] = tp++; }
bool hungary(int x) {
  for (edge *i = fst[x]; i; i = i->nxt)
    if (!flag[i->v]) {
      flag[i->v] = 1;
      if (!link[i->v] || hungary(link[i->v])) {
        link[i->v] = x;
        return 1;
      }
    }
  return 0;
}
bool augment(int x, int y, int k) {
  for (int i = 1; i <= n; ++i)
    if (a[i] == x && b[i] == y)
      --k;
    else if (a[i] == x && b[i] == -1 || b[i] == y && a[i] == -1)
      addedge(x * (n + 1) + y, i);
  for (; k > 0; --k) {
    memset(flag, 0, sizeof(flag));
    if (!hungary(x * (n + 1) + y)) {
      bool flag = 1;
      for (int i = 1; i <= n; ++i)
        if (a[i] == -1 && b[i] == -1) {
          a[i] = x, b[i] = y, flag = 0;
          break;
        }
      if (flag) return 0;
    }
  }
  return 1;
}
bool solve() {
  memset(maxd, 255, sizeof(maxd));
  memset(link, 0, sizeof(link));
  memset(cnt, 0, sizeof(cnt));
  tp = pool, memset(fst, 0, sizeof(fst));
  for (int i = 1; i <= n; ++i)
    if (b[i] != -1) {
      maxd[b[i]] = max(maxd[b[i]], max(a[i], 0));
      if (!a[i]) ++cnt[b[i]];
    }
  for (int i = 1; i <= n; ++i)
    if (maxd[i] > -1) {
      cnt[i] = max(cnt[i], i);
      if (!augment(0, i, cnt[i] % i ? cnt[i] + i - cnt[i] % i : cnt[i]))
        return 0;
      for (int j = 1; j <= maxd[i]; ++j)
        if (!augment(j, i, 1)) return 0;
    }
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; ++i) {
    if (link[i]) a[i] = link[i] / (n + 1), b[i] = link[i] % (n + 1);
    if ((a[i] == -1 || !a[i]) && b[i] == -1)
      a[i] = 0, b[i] = 1, maxd[1] = max(maxd[1], 0);
    if (a[i] == -1) a[i] = 1;
    if (a[i] > 0 && b[i] == -1)
      for (int j = 1; j <= n; ++j)
        if (maxd[j] + 1 >= a[i]) b[i] = j;
    if (b[i] == -1) return 0;
    if (!a[i]) {
      if (!cnt[b[i]]++)
        head[b[i]] = tail[b[i]] = i;
      else
        ans[tail[b[i]]] = i, tail[b[i]] = i;
      if (cnt[b[i]] == b[i]) cnt[b[i]] = 0, ans[i] = head[b[i]];
    }
  }
  for (int i = 1; i <= n; ++i)
    if (a[i])
      for (int j = 1; j <= n; ++j)
        if (a[j] == a[i] - 1 && b[i] == b[j]) {
          ans[i] = j;
          break;
        }
  return 1;
}
int main() {
  n = getint();
  static int c[310], d[310], t;
  for (int i = 1; i <= n; ++i) {
    c[i] = getint(), d[i] = getint();
    if (d[i] == -1 && c[i] > c[t]) t = i;
  }
  for (d[t] = 1; d[t] <= n && (d[t] == 1 || t); ++d[t]) {
    memcpy(a, c, sizeof(a));
    memcpy(b, d, sizeof(d));
    if (solve()) {
      for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
      return 0;
    }
  }
  puts("-1");
  return 0;
}