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;
using pii = pair<int, int>;
const int MAXN = 2010;
int n, pre[MAXN], cyc[MAXN];
int cnt[MAXN], maks[MAXN], m;
vector<int> e[MAXN];
pii p[MAXN];
int bio[MAXN], cookie, f[MAXN], max_x;
void add(int i, int a, int b) {
  for (int j = (0); j < (m); ++j)
    if ((a == -1 || p[j].first == a) && (b == -1 || p[j].second == b)) {
      e[i].push_back(n + j);
      e[n + j].push_back(i);
    }
}
void assign(int i, int a, int b) {
  pre[i] = a;
  cyc[i] = b;
}
int dfs(int first) {
  if (first == -1) return 1;
  if (bio[first] == cookie) return 0;
  bio[first] = cookie;
  for (int second : e[first])
    if (dfs(f[second])) {
      f[second] = first;
      return 1;
    }
  return 0;
}
bool done[MAXN];
int matching(void) {
  memset(f, -1, sizeof(f));
  memset(done, false, sizeof(done));
  int ret = 0;
  for (int i = (0); i < (n); ++i)
    if (pre[i] == 0 && cyc[i] != -1) {
      for (int j = (0); j < (m); ++j)
        if (f[n + j] == -1 && p[j].first == 0 && p[j].second == cyc[i]) {
          f[n + j] = i;
          done[i] = true;
          ++ret;
          break;
        }
    }
  for (int first = (0); first < (n); ++first) {
    if (done[first]) continue;
    ++cookie;
    if (dfs(first)) ++ret;
  }
  return ret;
}
void load() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); ++i) maks[i] = -2;
  for (int i = (0); i < (n); ++i) {
    char a[10], b[10];
    scanf("%s %s", a, b);
    pre[i] = cyc[i] = -1;
    if (a[0] != '?') sscanf(a, "%d", &pre[i]);
    if (b[0] != '?') sscanf(b, "%d", &cyc[i]);
    if (cyc[i] == -1 && pre[i] != -1) max_x = max(max_x, pre[i]);
    if (cyc[i] != -1) {
      if (pre[i] == 0) ++cnt[cyc[i]];
      maks[cyc[i]] = max(maks[cyc[i]], pre[i]);
    }
  }
}
int main(void) {
  load();
  for (int l = 1; l <= n; ++l) {
    m = 0;
    bool ok = true;
    for (int k = 1; k <= n; ++k)
      if (maks[k] != -2 || k == l) {
        int t = max(k, (cnt[k] + k - 1) / k * k);
        for (int j = (0); j < (t); ++j) p[m++] = {0, k};
        int to =
            (l == k && max_x != -1) ? max(maks[k], max_x) + 1 : maks[k] + 1;
        for (int j = (1); j < (to); ++j) p[m++] = {j, k};
        if (m > n) {
          ok = false;
          break;
        }
      }
    if (!ok) continue;
    for (int i = (0); i < (n + m); ++i) e[i].clear();
    for (int i = (0); i < (n); ++i) {
      add(i, pre[i], cyc[i]);
    }
    int match = matching();
    if (match != m) {
      continue;
    }
    for (int i = (n); i < (n + m); ++i) {
      assign(f[i], p[i - n].first, p[i - n].second);
    }
    for (int i = (0); i < (n); ++i)
      if ((pre[i] == -1 || pre[i] == 0) && cyc[i] == -1)
        assign(i, 0, 1);
      else if (pre[i] == -1)
        assign(i, 1, cyc[i]);
      else if (cyc[i] == -1)
        assign(i, pre[i], l);
    for (int k = (1); k < (n + 1); ++k) {
      int tot = 0;
      for (int i = (0); i < (n); ++i)
        if (pre[i] == 0 && cyc[i] == k) ++tot;
      assert(tot % k == 0);
    }
    for (int i = (0); i < (n); ++i)
      if (pre[i] == 0) {
        int k = cyc[i];
        int first = -1, c = 0;
        for (int j = (0); j < (i + 1); ++j) {
          if (cyc[j] != k || pre[j] != 0) continue;
          if (c % k == 0) first = j;
          ++c;
        }
        int nxt = -1;
        for (int j = (i + 1); j < (n); ++j)
          if (cyc[j] == k && pre[j] == 0) {
            nxt = j;
            break;
          }
        if (c % k == 0)
          printf("%d ", first + 1);
        else
          printf("%d ", nxt + 1);
      } else {
        for (int j = (0); j < (n); ++j)
          if (pre[j] == pre[i] - 1 && cyc[j] == cyc[i]) {
            printf("%d ", j + 1);
            break;
          }
      }
    printf("\n");
    return 0;
    break;
  }
  printf("-1\n");
  return 0;
}