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 strtoint(const string &x) {
  int r = 0;
  for (int i = 0; i < (int)x.size(); i++) r = r * 10 + (x[i] - '0');
  return r;
}
int getval(string &x) {
  if (x == "?")
    return -1;
  else
    return strtoint(x);
}
const int maxn = 310;
int precycle[maxn], cycle[maxn];
pair<int, int> format[maxn * 4];
int cnum[maxn], tower[maxn];
vector<int> con[maxn * 4];
int match[maxn], match2[maxn];
int used[maxn * 4];
int F;
bool dfs(int v) {
  if (used[v] == F) return 0;
  used[v] = F;
  for (int j : con[v])
    if (match2[j] == -1 || dfs(match2[j])) {
      match2[j] = v;
      return 1;
    }
  return 0;
}
bool ls(int a, int b) {
  int knowna = int(precycle[a] != -1) + int(cycle[a] != -1);
  int knownb = int(precycle[b] != -1) + int(cycle[b] != -1);
  if (knowna != knownb) return knowna > knownb;
  return (precycle[a] == -1 ? (int)1e9 : precycle[a]) <
         (precycle[b] == -1 ? (int)1e9 : precycle[b]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string u, v;
    cin >> u >> v;
    precycle[i] = getval(u);
    cycle[i] = getval(v);
  }
  vector<int> ord(n);
  for (int i = 0; i < n; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), ls);
  for (int fixi = 1; fixi <= n; fixi++) {
    bool ok = 1;
    int maxtower = -1;
    for (int i = 1; i <= n; i++) cnum[i] = 0, tower[i] = -1;
    for (int i = 0; i < n; i++) {
      if (cycle[i] != -1) {
        if (precycle[i] == 0) cnum[cycle[i]]++;
        tower[cycle[i]] = max(tower[cycle[i]], precycle[i]);
      }
      maxtower = max(maxtower, precycle[i]);
    }
    cnum[0] = 0;
    tower[0] = -1;
    for (int i = 1; i <= n; i++) cnum[i] = cnum[i] / i + (cnum[i] % i ? 1 : 0);
    for (int i = 0; i < n; i++)
      if (cycle[i] != -1) {
        cnum[cycle[i]] = max(cnum[cycle[i]], 1);
        tower[cycle[i]] = max(tower[cycle[i]], 0);
      }
    cnum[fixi] = max(1, cnum[fixi]);
    tower[fixi] = max(tower[fixi], maxtower);
    int vcnt = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < cnum[i] && vcnt < n * 2; j++)
        for (int k = 0; k < i && vcnt < n * 2; k++)
          format[vcnt++] = make_pair(i, 0);
      if (cnum[i] > 0) {
        for (int j = 1; j <= tower[i] && vcnt < n * 2; j++)
          format[vcnt++] = make_pair(i, j);
      }
    }
    if (vcnt > n) continue;
    for (int i = 0; i < n; i++) con[i].clear();
    for (int i = 0; i < vcnt; i++) {
      for (int j = 0; j < n; j++)
        if ((precycle[j] == -1 || precycle[j] == format[i].second) &&
            (cycle[j] == -1 || cycle[j] == format[i].first))
          con[j].push_back(i);
    }
    for (int i = 0; i < vcnt; i++) match2[i] = -1;
    F = 1;
    for (int i = 0; i < n; i++) used[i] = 0;
    for (int i = 0; i < n; i++) {
      F++;
      dfs(ord[i]);
    }
    for (int i = 0; i < n; i++) match[i] = -1;
    for (int j = 0; j < vcnt; j++)
      if (match2[j] != -1) match[match2[j]] = j;
    vector<int> covered(vcnt, -1);
    for (int i = 0; i < n; i++)
      if (match[i] != -1) covered[match[i]] = i;
    for (int i = 0; i < vcnt; i++)
      if (covered[i] == -1) {
        ok = 0;
      }
    if (!ok) continue;
    vector<int> ans(n, -1);
    for (int i = 1; i <= n; i++) {
      if (cnum[i] > 0) {
        vector<int> cur;
        for (int j = 0; j < n; j++)
          if (match[j] != -1 && format[match[j]] == make_pair(i, 0))
            cur.push_back(j);
        if ((int)cur.size() % i != 0) return 0;
        for (int j = 0; j < (int)cur.size(); j++)
          if (j % i == 0)
            ans[cur[j]] = cur[j + i - 1];
          else
            ans[cur[j]] = cur[j - 1];
      }
    }
    for (int i = 0; i < n; i++) {
      if (ans[i] == -1) {
        int a = cycle[i];
        int b = precycle[i];
        if (match[i] != -1) {
          a = format[match[i]].first;
          b = format[match[i]].second;
        }
        for (int j = 0; j < vcnt; j++)
          if ((a == -1 || format[j].first == a) &&
              (b == -1 || format[j].second == b - 1))
            ans[i] = covered[j];
        if (ans[i] == -1) {
          if (!(precycle[i] <= 0 && cycle[i] <= 1)) {
            cerr << precycle[i] << ' ' << cycle[i] << endl;
            return 0;
          }
          ans[i] = i;
        }
      }
    }
    for (int i = 0; i < n; i++) cout << ans[i] + 1 << " \n"[i == n - 1];
    return 0;
  }
  cout << -1 << endl;
  return 0;
}