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 c = 305;
int n, ut[c], kor[c], par[2 * c], pos = 1, szindb = 1, van[c][c], kell[c][c],
                                  ans[c], cnt;
bool v[2 * c];
pair<int, int> sor[2 * c];
bool szin[c];
bool dfs(int a) {
  v[a] = true;
  for (int i = n + 1; i <= cnt; i++) {
    if ((ut[a] != -1 && ut[a] != sor[i].first) ||
        (kor[a] != -1 && kor[a] != sor[i].second) || v[i]) {
      continue;
    }
    v[i] = 1;
    if (!par[i] || dfs(par[i])) {
      par[a] = i, par[i] = a;
      return true;
    }
  }
  return false;
}
bool solve() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      van[i][j] = 0, kell[i][j] = 0;
    }
  }
  for (int i = 1; i <= 2 * n; i++) {
    par[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int a = ut[i], b = kor[i];
    if (b == -1) {
      continue;
    }
    if (a != -1) {
      van[b][a]++;
      kell[b][a] = van[b][a];
    }
    if (!kell[b][0]) {
      kell[b][0]++;
    }
  }
  int ossz = 0;
  cnt = n;
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= 0; j--) {
      if (kell[i][j + 1] && !kell[i][j]) {
        kell[i][j] = 1;
      }
      if (j == 0) {
        while (kell[i][j] % i) {
          kell[i][j]++;
        }
      }
      if (kell[i][j]) {
      }
      ossz += kell[i][j] - van[i][j];
      if (ossz > n) {
        return 0;
      }
      for (int k = 1; k <= kell[i][j] - van[i][j]; k++) {
        cnt++;
        sor[cnt] = {j, i};
      }
    }
  }
  int pardb = 0;
  for (int i = 1; i <= n; i++) {
    if (kor[i] != -1 && ut[i] != -1) {
      continue;
    }
    for (int i = 1; i <= cnt; i++) {
      v[i] = 0;
    }
    pardb += dfs(i);
  }
  if (pardb != cnt - n) {
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (par[i]) {
      if (ut[i] == -1) {
        ut[i] = sor[par[i]].first;
      }
      if (kor[i] == -1) {
        kor[i] = sor[par[i]].second;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!par[i] && (ut[i] == -1 || kor[i] == -1)) {
      int a = ut[i], b = kor[i];
      if (b == -1) {
        if (a == -1 || a == 0) {
          kor[i] = 1, ut[i] = 0;
        } else {
          kor[i] = kor[pos];
        }
      } else {
        ut[i] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (ut[i] != 0) {
      for (int j = 1; j <= n; j++) {
        if (kor[i] == kor[j] && ut[j] + 1 == ut[i]) {
          ans[i] = j;
        }
      }
    } else {
      int cnt = 0, veg = 0;
      for (int j = 1; j <= i; j++) {
        if (kor[i] == kor[j] && ut[i] == ut[j]) {
          if (cnt % kor[j] == 0) {
            veg = j;
          }
          cnt++;
        }
      }
      if (cnt % kor[i] == 0) {
        ans[i] = veg;
      } else {
        for (int j = i + 1; j <= n; j++) {
          if (kor[i] == kor[j] && ut[i] == ut[j]) {
            ans[i] = j;
            break;
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return true;
}
string s;
int cin2() {
  string s;
  cin >> s;
  if (s[0] == '?') {
    return -1;
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    int x = (s[i] - '0');
    ans *= 10, ans += x;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  szin[1] = 1;
  for (int i = 1; i <= n; i++) {
    ut[i] = cin2(), kor[i] = cin2();
    if (ut[i] > ut[pos]) {
      pos = i;
    }
    if (kor[i] != -1) {
      if (!szin[kor[i]]) {
        szindb++;
      }
      szin[kor[i]] = 1;
    }
  }
  if (szindb > 25) {
    cout << -1 << "\n";
    return 0;
  }
  if (kor[pos] != -1) {
    if (solve()) {
      return 0;
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (szin[i]) {
        kor[pos] = i;
        if (solve()) {
          return 0;
        }
      }
    }
  }
  cout << -1 << "\n";
  return 0;
}