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;
struct point {
  int next, to, w;
} ar[650 * 650];
char s[650];
bool is[650];
int pre[650], len[650], b1, b2, n;
int dep[650], T[650], head1[650];
int ps, pt, a5[650], a6[650], ans[650];
int tot, head[650], art, a4[650][650];
vector<int> a[4], a1[650], a2[650][650], a3[650];
inline void deal(), link(int, int, int);
inline bool bfs();
inline int dfs(int, int);
template <class free>
inline void Max(free&, free);
int main() {
  scanf("%d", &n);
  for (int i(1); i <= n; ++i) {
    scanf("%s", s);
    if (s[0] ^ '?')
      sscanf(s, "%d", &pre[i]);
    else
      pre[i] = -1;
    scanf("%s", s);
    if (s[0] ^ '?')
      sscanf(s, "%d", &len[i]);
    else
      len[i] = -1;
  }
  for (int i(1); i <= n; ++i) {
    if (~pre[i] && ~len[i])
      a[0].push_back(i);
    else if (~pre[i])
      a[1].push_back(i);
    else if (~len[i])
      a[2].push_back(i);
    else
      a[3].push_back(i);
  }
  for (int i(0); i < a[1].size(); ++i)
    if (!b1 || pre[b1] < pre[a[1][i]]) b1 = a[1][i];
  for (int i(0); i < a[1].size(); ++i)
    if (a[1][i] == b1) {
      a[1].erase(a[1].begin() + i);
      break;
    }
  for (int i(1); i <= n; ++i)
    if (~len[i]) a1[len[i]].push_back(i);
  for (int i(1); i <= n; ++i) {
    if (b1) a1[i].push_back(b1);
    b2 = i;
    if (deal(), b1) a1[i].pop_back();
  }
  return puts("-1"), 0;
}
inline int dfs(int x, int f) {
  if (x == pt) return f;
  int r(f);
  for (int &i(head1[x]), j, i1; i; i = ar[i].next)
    if (ar[i].w && dep[i1 = ar[i].to] == dep[x] + 1) {
      j = dfs(i1, min(r, ar[i].w));
      ar[i].w -= j, ar[i ^ 1].w += j, r -= j;
      if (!r) return f;
    }
  return f - r;
}
inline bool bfs() {
  memset(dep, 0, sizeof(dep));
  int L(0), R(1);
  dep[T[1] = ps] = 1;
  while (L++ ^ R)
    for (int i(head[T[L]]), i1; i; i = ar[i].next)
      if (ar[i].w && !dep[i1 = ar[i].to]) {
        dep[i1] = dep[T[L]] + 1, T[++R] = i1;
        if (i1 == pt) return memcpy(head1, head, sizeof(head)), true;
      }
  return false;
}
template <class free>
inline void Max(free& x, free y) {
  x = x > y ? x : y;
}
inline void link(int u, int v, int w) {
  ar[++art] = {head[u], v, w}, head[u] = art;
  ar[++art] = {head[v], u, 0}, head[v] = art;
}
inline void deal() {
  memset(a4, 0, sizeof(a4));
  memset(a5, -1, sizeof(a5));
  memset(head, tot = 0, sizeof(head));
  art = 1, ps = ++tot, pt = ++tot;
  for (int i(1), j; i <= n; ++i) {
    for (j = 0; j <= n; ++j) vector<int>().swap(a2[i][j]);
    vector<int>().swap(a3[i]);
  }
  for (int i(1), i1, j; i <= n; ++i)
    for (j = 0; j < a1[i].size(); ++j)
      if (~pre[i1 = a1[i][j]])
        a2[i][pre[i1]].push_back(i1), Max(a5[i], pre[i1]);
      else
        a3[i].push_back(i1);
  int sum(0);
  for (int i(1), j; i <= n; ++i) {
    if (!a1[i].size()) continue;
    for (j = i; j < a2[i][0].size(); j += i)
      ;
    link(a4[i][0] = ++tot, pt, j - a2[i][0].size()), Max(a5[i], 0);
    for (sum += ar[art ^ 1].w, j = 1; j <= a5[i]; ++j) {
      if (a2[i][j].size()) continue;
      link(a4[i][j] = ++tot, pt, 1), ++sum;
      if (sum > n) return;
    }
  }
  for (int i(1), j, k; i <= n; ++i)
    for (j = 0; j < a3[i].size(); ++j) {
      link(ps, ++tot, 1), a6[tot] = a3[i][j];
      for (k = 0; k <= a5[i]; ++k)
        if (a4[i][k]) link(tot, a4[i][k], 1);
    }
  for (int i(0), j; i < a[1].size(); ++i) {
    link(ps, ++tot, 1), a6[tot] = a[1][i];
    for (j = 1; j <= n; ++j)
      if (a4[j][pre[a[1][i]]]) link(tot, a4[j][pre[a[1][i]]], 1);
  }
  for (int i(0), j, k; i < a[3].size(); ++i) {
    for (link(ps, ++tot, 1), j = 1; j <= n; ++j)
      for (k = 0; k <= a5[j]; ++k)
        if (a4[j][k]) link(tot, a4[j][k], 1);
    a6[tot] = a[3][i];
  }
  int flow, maxflow(0);
  while (bfs())
    while (flow = dfs(ps, 0x3f3f3f3f)) maxflow += flow;
  if (sum ^ maxflow) return;
  for (int i(1), j, k; i <= n; ++i)
    for (j = 0; j <= a5[i]; ++j)
      if (a4[i][j])
        for (k = head[a4[i][j]]; k; k = ar[k].next)
          if (ar[k].w) a2[i][j].push_back(a6[ar[k].to]), is[a6[ar[k].to]] = 1;
  for (int i(1), j; i <= n; ++i)
    for (j = 0; j < a3[i].size(); ++j) {
      if (is[a3[i][j]]) continue;
      a2[i][1].push_back(a3[i][j]), Max(a5[i], 1);
    }
  for (int i(0); i < a[1].size(); ++i) {
    if (is[a[1][i]]) continue;
    if (!pre[a[1][i]])
      ans[a[1][i]] = a[1][i];
    else
      a2[b2][pre[a[1][i]]].push_back(a[1][i]);
  }
  for (int i(0); i < a[3].size(); ++i) {
    if (is[a[3][i]]) continue;
    ans[a[3][i]] = a[3][i];
  }
  for (int i(1), j, k; i <= n; ++i) {
    if (!a1[i].size()) continue;
    for (j = 1; j < a2[i][0].size(); ++j) ans[a2[i][0][j]] = a2[i][0][j - 1];
    for (j = 0; j < a2[i][0].size(); j += i)
      ans[a2[i][0][j]] = a2[i][0][j + i - 1];
    for (j = 1; j <= a5[i]; ++j)
      for (k = 0; k < a2[i][j].size(); ++k)
        ans[a2[i][j][k]] = a2[i][j - 1].front();
  }
  for (int i(1); i <= n; ++i) printf("%d ", ans[i]);
  exit(0);
}