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>
template <int xn, int xe>
struct flow {
  int head[xn], next[xe], to[xe], fl[xe], N, E, q[xn + 1], dep[xn];
  void clear(int n) {
    N = n, E = 0;
    for (int i = 0; i < N; i++) head[i] = -1;
  }
  inline void add(int u, int v, int f) {
    next[E] = head[u], to[E] = v, fl[E] = f, head[u] = E++;
    next[E] = head[v], to[E] = u, fl[E] = 0, head[v] = E++;
  }
  bool BFS() {
    for (int i = 0; i < N; i++) dep[i] = 0;
    int *H = q, *T = q + 1, u;
    dep[ *T = 0] = 1;
    while (H < T)
      for (int e = head[u = *++H]; ~e; e = next[e])
        if (fl[e] && !dep[to[e]]) {
          dep[ *++T = to[e]] = dep[u] + 1;
          if (*T == N - 1) return 1;
        }
    return 0;
  }
  int DFS(int p, int f) {
    if (p == N - 1) return f;
    int u = 0, y;
    for (int e = head[p]; ~e; e = next[e])
      if (fl[e] && dep[to[e]] == dep[p] + 1)
        if (y = DFS(to[e], std::min(f, fl[e]))) {
          fl[e] -= y, fl[e ^ 1] += y;
          u += y, f -= y;
          if (!f) return u;
        }
    if (!u) dep[p] = 0;
    return u;
  }
  int operator()() {
    int r = 0;
    while (BFS()) r += DFS(0, 1000000000);
    return r;
  }
};
const int xn = 301;
flow<xn * 2, xn * 20> G;
std::vector<int> bycl[xn], udis[xn], need[xn], ucl[xn], DIS0;
int N, dis[xn], cl[xn], c0[xn], ext[xn], son, soff, sall, U[xn], dep__[xn],
    ANS[xn], CLEXI[xn], INPUT_cl[xn], INPUT_dis[xn];
int I(int _) {
  char c = getchar();
  while ((c < 48 || c > 57) && c != '?') c = getchar();
  if (c == '?') return _;
  int r = 0;
  while (c > 47 && c < 58) r = (r << 3) + r + r + c - 48, c = getchar();
  return r;
}
int Main(int x) {
  for (int i = 0; i <= N; i++) {
    bycl[i].clear();
    udis[i].clear();
    need[i].clear();
    ucl[i].clear();
    c0[i] = ext[i] = U[i] = dep__[i] = ANS[i] = 0;
  }
  DIS0.clear();
  son = soff = sall = 0;
  bool HAVE_CL = 0;
  for (int i = 1; i <= N; i++) cl[i] = INPUT_cl[i], dis[i] = INPUT_dis[i];
  for (int i = 1; i <= N; i++) {
    bycl[cl[i]].push_back(i);
    if (!~dis[i]) udis[cl[i]].push_back(i);
    if (!cl[i] && ~dis[i]) ucl[dis[i]].push_back(i);
    if (!dis[i])
      c0[cl[i]]++;
    else
      ext[cl[i]] = std::max(ext[cl[i]], dis[i]);
  }
  for (int i = 1; i <= N; i++)
    if (!bycl[i].empty()) HAVE_CL = 1, c0[i] = std::max((c0[i] + i - 1) / i, 1);
  if (!HAVE_CL) c0[1] = 1;
  ext[x] = std::max(ext[x], ext[0]);
  int xext = 1;
  while (!c0[xext]) xext++;
  for (int i = xext + 1; i <= N; i++)
    if (ext[i] > ext[xext]) xext = i;
  if (ext[0] > ext[xext]) ext[xext] = ext[0];
  for (int i = 1; i <= N; i++) {
    if (dis[i] <= 0) son++;
    if (!!dis[i]) soff++;
    sall++;
  }
  for (int i = 1; i <= N; i++) {
    if ((son -= c0[i] * i) < 0) return 0;
    if ((soff -= ext[i]) < 0) return 0;
    if ((sall -= c0[i] * i + ext[i]) < 0) return 0;
  }
  for (int i = 1; i <= N; i++)
    if (c0[i]) {
      need[i].resize(ext[i] + 1);
      for (int j = 1; j <= ext[i]; j++) need[i][j] = 1;
      need[i][0] = c0[i] * i;
      for (auto j : bycl[i])
        if (~dis[j] && need[i][dis[j]] > 0) need[i][dis[j]]--;
      for (int j = 0; j <= ext[i]; j++) U[j] += need[i][j];
    }
  for (auto i : bycl[0])
    if (~dis[i] && U[dis[i]] > 0) U[dis[i]]--;
  G.clear(1 + N + N + 1);
  for (int i = 1; i <= N; i++)
    if (c0[i]) {
      if (udis[i].size()) G.add(0, i, udis[i].size());
      for (int j = 0; j <= ext[i]; j++)
        if (need[i][j] > 0) G.add(i, N + j + 1, need[i][j]);
    }
  for (int i = 0; i < N; i++)
    if (U[i]) G.add(N + i + 1, G.N - 1, U[i]);
  G();
  for (int i = 1; i <= N; i++)
    if (udis[i].size())
      for (int e = G.head[i]; ~e; e = G.next[e])
        if (G.to[e] > N && G.to[e] <= N + N)
          for (int TIME = G.fl[e ^ 1]; TIME--;) {
            int use = udis[i].back();
            udis[i].resize(udis[i].size() - 1);
            dis[use] = G.to[e] - N - 1;
            need[i][G.to[e] - N - 1]--;
          }
  for (int i = 1; i <= N; i++)
    if (c0[i])
      for (int j = 0; j <= ext[i]; j++)
        while (need[i][j] > 0 && !ucl[j].empty()) {
          int use = ucl[j].back();
          ucl[j].resize(ucl[j].size() - 1);
          cl[use] = i;
          need[i][j]--;
        }
  for (int i = 1; i <= N; i++)
    if (c0[i])
      for (int j = 0; j <= ext[i]; j++)
        while (need[i][j] > 0) {
          if (udis[0].empty()) return 0;
          int use = udis[0].back();
          udis[0].resize(udis[0].size() - 1);
          dis[use] = j, cl[use] = i;
          need[i][j]--;
        }
  for (int i = 1; i <= N; i++)
    if (!~dis[i] && !cl[i])
      dis[i] = 0, cl[i] = 1;
    else if (!~dis[i])
      dis[i] = 1;
    else if (!cl[i])
      cl[i] = xext;
  for (int i = 1; i <= N; i++) bycl[i].clear();
  for (int i = 1; i <= N; i++) bycl[cl[i]].push_back(i);
  for (int i = 1; i <= N; i++)
    if (!bycl[i].empty()) {
      DIS0.clear();
      for (auto j : bycl[i]) {
        if (!dis[j]) DIS0.push_back(j);
        dep__[dis[j]] = j;
      }
      for (int j = 0; j < DIS0.size(); j++)
        ANS[DIS0[j]] = DIS0[j % i ? j - 1 : j + i - 1];
      for (auto j : bycl[i])
        if (dis[j]) ANS[j] = dep__[dis[j] - 1];
    }
  for (int i = 1; i <= N; i++) printf("%d ", ANS[i]);
  puts("");
  return 1;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    INPUT_dis[i] = dis[i] = I(-1), INPUT_cl[i] = cl[i] = I(0);
    CLEXI[cl[i]]++;
  }
  if (CLEXI[0] == N) CLEXI[1] = 1;
  for (int i = 1; i <= N; i++)
    if (CLEXI[i])
      if (Main(i)) return 0;
  puts("-1");
  return 0;
}