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 N = 305;
int n, m, mx, len[N], dis[N], fa[N], x[N], y[N], cnt[N], mxd[N];
int e[N][N], vis[N], l[N], r[N], mat[N];
vector<int> v[N];
char s1[5], s2[5];
inline int get_int(char *s) {
  int ret;
  sscanf(s, "%d", &ret);
  return ret;
}
int dfs(int pos) {
  for (int i = 1; i <= m; i++)
    if (e[pos][i] && !vis[i] && !r[i]) {
      vis[i] = 1;
      if (!mat[i] || dfs(mat[i])) {
        mat[i] = pos;
        return 1;
      }
    }
  return 0;
}
int check(int pos) {
  memset(e, 0, sizeof(e));
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(mat, 0, sizeof(mat));
  m = 0;
  for (int i = 1; i <= n; i++)
    if (mxd[i] != -1 || i == pos) {
      int c = cnt[i], lt = mxd[i];
      if (i == pos) c = max(c, i), lt = max(lt, mx);
      for (int j = 1; j <= c; j++)
        if (++m > n)
          return 0;
        else
          x[m] = i, y[m] = 0;
      for (int j = 1; j <= lt; j++)
        if (++m > n)
          return 0;
        else
          x[m] = i, y[m] = j;
    }
  int ret = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      e[i][j] =
          (len[i] == x[j] || len[i] == -1) && (dis[i] == y[j] || dis[i] == -1);
      if (len[i] == x[j] && dis[i] == y[j] && !l[i] && !r[j])
        l[i] = r[j] = 1, mat[j] = i, ++ret;
    }
  for (int i = 1; i <= n; i++)
    if (!l[i]) memset(vis, 0, sizeof(vis)), ret += dfs(i);
  return ret == m;
}
void print(int tt) {
  for (int i = 1; i <= m; i++) len[mat[i]] = x[i], dis[mat[i]] = y[i];
  for (int i = 1; i <= n; i++)
    if (len[i] == -1) {
      if (dis[i] <= 0)
        dis[i] = 0, len[i] = 1;
      else
        len[i] = tt;
    } else if (dis[i] == -1)
      dis[i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (len[i] == len[j] && dis[i] == dis[j] + 1) {
        fa[i] = j;
        break;
      }
  for (int i = 1; i <= n; i++)
    if (!dis[i]) {
      v[len[i]].push_back(i);
      if (int(v[len[i]].size()) == len[i]) {
        for (int j = 0; j < len[i]; j++)
          fa[v[len[i]][j]] = v[len[i]][(j + 1) % len[i]];
        v[len[i]].clear();
      }
    }
  for (int i = 1; i <= n; i++) cout << fa[i] << ' ';
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  memset(mxd, -1, sizeof(mxd));
  for (int i = 1; i <= n; i++) {
    cin >> s1 >> s2;
    dis[i] = s1[0] == '?' ? -1 : get_int(s1);
    len[i] = s2[0] == '?' ? -1 : get_int(s2);
    if (len[i] != -1) {
      mxd[len[i]] = max(mxd[len[i]], max(dis[i], 0));
      if (!dis[i]) ++cnt[len[i]];
    } else
      mx = max(mx, dis[i]);
  }
  for (int i = 1; i <= n; i++) cnt[i] = max(1, (cnt[i] + i - 1) / i) * i;
  for (int i = 1; i <= n; i++)
    if (check(i)) {
      print(i);
      return 0;
    }
  cout << -1 << endl;
  return 0;
}