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>
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar()) {
    if (_ch == '?') return -1;
  }
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int n, cnt, tot;
int L[305], c[305];
std::vector<int> t[305][305];
std::pair<int, int> B[305];
int vis[305];
int G[305][305];
inline bool cmp(int A, int B) { return A == -1 || A == B; }
int bel[305];
inline bool dfs(int u) {
  for (int i = 1; i <= n; i++)
    if (G[u][i] && !vis[i]) {
      vis[i] = 1;
      if ((!bel[i]) || (dfs(bel[i]))) {
        bel[i] = u;
        return 1;
      }
    }
  return 0;
}
inline bool hungary() {
  for (int i = 1; i <= tot; i++) {
    memset(vis, 0, sizeof(vis));
    if (!dfs(i)) {
      return 0;
    }
  }
  return 1;
}
int to[305];
bool check() {
  memset(vis, -1, sizeof vis);
  memset(bel, 0, sizeof bel);
  memset(to, 0, sizeof to);
  memset(G, 0, sizeof G);
  tot = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) t[i][j].clear();
  }
  for (int i = 1; i <= n; i++) {
    if (L[i] != -1 && c[i] != -1) {
      t[c[i]][L[i]].push_back(i);
    }
    if (c[i] != -1) vis[c[i]] = std::max(vis[c[i]], L[i] == -1 ? 0 : L[i]);
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] != -1) {
      for (int j = 1; j <= vis[i]; j++)
        if (t[i][j].empty()) {
          B[++tot] = std::make_pair(j, i);
          if (tot > n) {
            return 0;
          }
        }
      int V = t[i][0].size() == 0 ? i : i - t[i][0].size() % i;
      if (V == i && t[i][0].size() > 0) V = 0;
      for (int j = 1; j <= V; j++) {
        B[++tot] = std::make_pair(0, i);
        if (tot > n) {
          return 0;
        }
      }
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= tot; j++)
      if (L[i] == -1 || c[i] == -1) {
        if (cmp(L[i], B[j].first) && cmp(c[i], B[j].second)) G[j][i] = 1;
      }
  }
  if (!hungary()) return 0;
  for (int i = 1; i <= n; i++)
    if (bel[i]) {
      L[i] = B[bel[i]].first, c[i] = B[bel[i]].second;
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) t[i][j].clear();
  }
  for (int i = 1; i <= n; i++) {
    if (c[i] != -1 && L[i] != -1) t[c[i]][L[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < t[i][0].size(); j++) {
      if (j % i == 0)
        to[t[i][0][j]] = t[i][0][j + i - 1];
      else
        to[t[i][0][j]] = t[i][0][j - 1];
    }
    for (int j = 1; j <= n; j++) {
      for (auto k : t[i][j]) {
        to[k] = t[i][j - 1][0];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (L[i] == -1 && c[i] != -1) {
      to[i] = t[c[i]][0][0];
    }
    if (L[i] > 0 && c[i] == -1) {
      for (int j = 1; j <= n; j++)
        if (!t[j][L[i] - 1].empty()) {
          to[i] = t[j][L[i] - 1][0];
        }
      if (!to[i]) {
        return 0;
      }
    }
    if (L[i] <= 0 && c[i] == -1) to[i] = i;
  }
  for (int i = 1; i <= n; i++) wrt(to[i], ' ');
  putchar('\n');
  exit(0);
}
int main() {
  n = rd();
  for (int i = 1; i <= n; i++) L[i] = rd(), c[i] = rd();
  int pos = 1;
  for (int i = 2; i <= n; i++)
    if (L[i] > L[pos]) pos = i;
  if (c[pos] != -1)
    check();
  else {
    for (int i = 1; i <= n; i++) {
      c[pos] = i;
      check();
    }
  }
  wrt(-1, '\n');
}