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
#include <bits/stdc++.h>
const int N = 307;
int max(int a, int b) { return a > b ? a : b; }
int n, m, mx, len[N], dis[N], fa[N], x[N], y[N], cnt[N], mxd[N], e[N][N],
    vis[N], L[N], R[N], mat[N];
std::vector<int> vec[N];
char s1[5], s2[5];
int dfs(int u) {
  for (int v = 1; v <= m; ++v)
    if (e[u][v] && !vis[v] && !R[v])
      if (vis[v] = 1, !mat[v] || dfs(mat[v])) return mat[v] = u, 1;
  return 0;
}
int check(int p) {
  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] || i == p) {
      int c = cnt[i], l = mxd[i];
      if (i == p) c = max(c, i), l = max(l, mx);
      for (int j = 1; j <= c; ++j) {
        if (++m > n) return 0;
        x[m] = i, y[m] = 0;
      }
      for (int j = 1; j <= l; j++) {
        if (++m > n) return 0;
        x[m] = i, y[m] = j;
      }
    }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      e[i][j] = (len[i] == x[j] || !~len[i]) && (dis[i] == y[j] || !~dis[i]);
      if (len[i] == x[j] && dis[i] == y[j] && !L[i] && !R[j])
        L[i] = R[j] = 1, mat[j] = i, ++ans;
    }
  for (int i = 1; i <= n; ++i)
    if (!L[i]) memset(vis, 0, sizeof vis), ans += dfs(i);
  return ans == m;
}
void print(int p) {
  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])
      if (dis[i] <= 0)
        dis[i] = 0, len[i] = 1;
      else
        len[i] = p;
    else if (!~dis[i])
      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]) {
      vec[len[i]].push_back(i);
      if ((int)vec[len[i]].size() == len[i]) {
        for (int j = 0; j < len[i]; ++j)
          fa[vec[len[i]][j]] = vec[len[i]][(j + 1) % len[i]];
        vec[len[i]].clear();
      }
    }
  for (int i = 1; i <= n; ++i) printf("%d ", fa[i]);
}
int main() {
  scanf("%d", &n), memset(mxd, -1, sizeof mxd);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%s", s1, s2), dis[i] = s1[0] == '?' ? -1 : std::atoi(s1),
                           len[i] = s2[0] == '?' ? -1 : std::atoi(s2);
    if (~len[i]) {
      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)) return print(i), 0;
  puts("-1");
}
