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 = 310;
void read(int &first) {
  first = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '?') {
      first = -1;
      return;
    }
    c = getchar();
  }
  while ('0' <= c && c <= '9') first = first * 10 + c - '0', c = getchar();
}
int n, pc[N], c[N], cnt[N], dis[N], need[N];
bool vis[N];
int id[N][N], d[N][N], tl, C[N * N], PC[N * N];
bool a[N][N];
int match[N];
inline bool same(int a, int b) { return a == b || a == -1 || b == -1; }
bool mx[N], my[N], vs[N];
bool dfs(int first) {
  for (int i = 1; i <= n; i++)
    if (match[i] != first && !my[i] && !vs[i] && a[first][i]) {
      vs[i] = true;
      if (!match[i] || dfs(match[i])) {
        match[i] = first;
        return true;
      }
    }
  return false;
}
bool solve(int first, int D) {
  tl = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= need[i]; j++) id[i][j] = ++tl, C[tl] = i, PC[tl] = 0;
  for (int i = 1; i <= n; i++) {
    int d1 = (i == first) ? max(dis[i], D) : dis[i];
    for (int j = 1; j <= d1; j++) d[i][j] = ++tl, C[tl] = i, PC[tl] = j;
  }
  if (tl > n) return false;
  memset(match, 0, sizeof(match));
  memset(a, false, sizeof(a));
  memset(mx, false, sizeof(mx));
  memset(my, false, sizeof(my));
  for (int i = 1; i <= tl; i++)
    for (int j = 1; j <= n; j++)
      if (same(C[i], c[j]) && same(PC[i], pc[j])) {
        a[i][j] = true;
        if (C[i] == c[j] && PC[i] == pc[j] && !mx[i] && !my[j]) {
          mx[i] = my[j] = true;
          match[j] = i;
        }
      }
  for (int i = 1; i <= n; i++)
    if (~c[i] && !pc[i] && !my[i]) return false;
  for (int i = 1; i <= tl; i++)
    if (!mx[i]) {
      memset(vs, false, sizeof(vs));
      if (!dfs(i)) return false;
    }
  return true;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(pc[i]), read(c[i]);
  int mxd = 0;
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    if (~c[i] && !pc[i]) cnt[c[i]]++;
    if (~c[i]) vis[c[i]] = true, flag = true;
    if (~c[i] && ~pc[i]) dis[c[i]] = max(dis[c[i]], pc[i]);
    mxd = max(mxd, pc[i]);
  }
  if (!flag) vis[1] = true;
  for (int i = 1; i <= n; i++)
    if (vis[i]) need[i] = (!cnt[i]) ? i : (cnt[i] + i - 1) / i * i;
  bool haveans = false;
  int X = 0;
  for (int i = 1; i <= n; i++)
    if (vis[i]) {
      if (solve(i, mxd)) {
        haveans = true;
        X = i;
        break;
      }
    }
  if (haveans) {
    for (int i = 1; i <= n; i++)
      if (match[i])
        c[i] = C[match[i]], pc[i] = PC[match[i]];
      else {
        if ((!pc[i] || pc[i] == -1) && c[i] == -1)
          c[i] = 1, pc[i] = 0;
        else if (c[i] == -1)
          c[i] = X;
        else if (pc[i] == -1)
          pc[i] = 1;
      }
    vector<int> cir[N];
    vector<int> d[N][N];
    for (int i = 1; i <= n; i++)
      if (!pc[i])
        cir[c[i]].push_back(i);
      else
        d[c[i]][pc[i]].push_back(i);
    static int fa[N];
    for (int i = 1; i <= n; i++) {
      int len = cir[i].size();
      for (int j = 0; j < len; j++)
        fa[cir[i][j]] = (j % i == 0) ? cir[i][j + i - 1] : cir[i][j - 1];
      for (int j = 1; j <= n; j++) {
        int len = d[i][j].size();
        if (len) {
          int pre = (j == 1) ? cir[i][0] : d[i][j - 1][0];
          for (int k = 0; k < len; k++) fa[d[i][j][k]] = pre;
        }
      }
    }
    for (int i = 1; i <= n; i++) printf("%d ", fa[i]);
    printf("\n");
  } else
    printf("-1\n");
  return 0;
}