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 inf = 2e9;
const long long Inf = 1e10;
const int N = 1005;
inline long long IN() {
  long long x = 0;
  int ch = 0, f = 0;
  for (ch = getchar(); (ch != '?') && ch != -1 && (ch < 48 || ch > 57);
       ch = getchar())
    f = (ch == '-');
  if (ch == '?') return -1;
  for (; ch >= 48 && ch <= 57; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return f ? (-x) : x;
}
template <typename T>
inline int chkmin(T &a, const T &b) {
  if (b < a) return a = b, 1;
  return 0;
}
template <typename T>
inline int chkmax(T &a, const T &b) {
  if (b > a) return a = b, 1;
  return 0;
}
int Pow(int x, int y, int p) {
  int a = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) a = (long long)a * x % p;
  return a;
}
int ter[N], n;
int rst[N], app[N], hasc;
int now[N], C[N], P[N], F[N];
int mx[N], tmp, has[N], fre;
struct node {
  int pc, cy;
} a[N];
int liu[N];
namespace Graph {
int cnt = 0, S, T;
struct edge {
  int v, w, pre;
} e[1000005];
int dex, adj[100005];
int dis[100005], que[100005], r;
void init() {
  dex = 1;
  for (int i = (int)(1); i <= (int)(cnt); i++) adj[i] = 0;
  cnt = 0;
  S = ++cnt;
  T = ++cnt;
}
void adde(int x, int y, int w) {
  e[++dex] = (edge){y, w, adj[x]};
  adj[x] = dex;
  e[++dex] = (edge){x, 0, adj[y]};
  adj[y] = dex;
}
int bfs(int S, int T) {
  for (int i = (int)(1); i <= (int)(cnt); i++) dis[i] = -1;
  dis[que[r = 1] = S] = 0;
  for (int l = (int)(1); l <= (int)(r); l++) {
    int u = que[l];
    if (u == T) return 1;
    for (int i = adj[u]; i; i = e[i].pre)
      if (e[i].w) {
        int v = e[i].v;
        if (dis[v] < 0) dis[que[++r] = v] = dis[u] + 1;
      }
  }
  return 0;
}
int dfs(int x, int f) {
  if (x == T) return f;
  int ret = 0;
  for (int i = adj[x]; i; i = e[i].pre)
    if (e[i].w) {
      int v = e[i].v;
      if (dis[v] == dis[x] + 1) {
        int F = dfs(v, min(f - ret, e[i].w));
        e[i].w -= F;
        e[i ^ 1].w += F;
        ret += F;
        if (ret == f) return ret;
      }
    }
  if (!ret) dis[x] = -1;
  return ret;
}
int maxf() {
  int ans = 0;
  while (bfs(S, T)) ans += dfs(S, 1 << 30);
  return ans;
}
void check(int l, int r) {
  for (int i = (int)(l); i <= (int)(r); i++) liu[i] = 0;
  for (int i = adj[S]; i; i = e[i].pre)
    if (!e[i].w) {
      int k = e[i].v;
      for (int u = adj[k]; u; u = e[u].pre) {
        if (e[u].w < (1 << 30)) {
          liu[k] = e[u].v;
          break;
        }
      }
    }
}
};  // namespace Graph
int gg[N], mst[N];
bool hav[N][N];
vector<int> cyc[N];
int ans[N];
int prm[N][N], id[N];
int eq(int x, int y) { return (x == y) || (x < 0) || (y < 0); }
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) {
    a[i].pc = IN();
    a[i].cy = IN();
    if (a[i].cy != -1) {
      app[a[i].cy] = 1;
      hasc = 1;
    }
    if (a[i].pc != -1 && a[i].cy != -1) {
      ter[i] = 1;
      if (!a[i].pc) {
        ++has[a[i].cy];
      } else {
        chkmax(mx[a[i].cy], a[i].pc);
      }
    } else if (a[i].cy != -1 && a[i].pc == -1) {
      ++rst[a[i].cy];
    } else if (a[i].pc != -1 && a[i].cy == -1) {
      tmp = max(tmp, a[i].pc);
    } else {
      ++fre;
    }
  }
  if (!hasc) {
    app[1] = 1;
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    if (app[i]) {
      if (!has[i])
        mst[i] = i;
      else
        mst[i] = (has[i] + i - 1) / i * i - has[i];
    }
  for (int i = (int)(1); i <= (int)(n); i++) gg[i] = mx[i];
  for (int cho = (int)(1); cho <= (int)(n); cho++)
    if (app[cho]) {
      for (int j = (int)(1); j <= (int)(n); j++) now[j] = mx[j];
      memset(hav, 0, sizeof hav);
      memset(id, 0, sizeof id);
      Graph ::init();
      int &cnt = Graph ::cnt, mm = 0;
      chkmax(now[cho], tmp);
      for (int j = (int)(1); j <= (int)(n); j++)
        if (ter[j]) hav[a[j].cy][a[j].pc] = 1;
      for (int j = (int)(1); j <= (int)(n); j++)
        if (app[j]) {
          for (int k = (int)(1); k <= (int)(now[j]); k++) {
            if (!hav[j][k]) {
              ++cnt;
              C[cnt] = j;
              P[cnt] = k;
              mm++;
              Graph ::adde(cnt, Graph ::T, 1);
            }
          }
        }
      for (int j = (int)(1); j <= (int)(n); j++)
        if (app[j]) {
          ++cnt;
          C[cnt] = j;
          P[cnt] = 0;
          mm += mst[j];
          Graph ::adde(cnt, Graph ::T, mst[j]);
        }
      int nn = cnt;
      for (int j = (int)(1); j <= (int)(n); j++)
        if (!ter[j]) {
          ++cnt;
          id[j] = cnt;
          Graph ::adde(Graph ::S, cnt, 1);
          int u = a[j].cy, v = a[j].pc;
          for (int k = (int)(3); k <= (int)(nn); k++) {
            if (eq(u, C[k]) && eq(v, P[k])) {
              Graph ::adde(cnt, k, 1 << 30);
            }
          }
        }
      if (Graph ::maxf() == mm) {
        Graph ::check(nn + 1, cnt);
        for (int j = (int)(1); j <= (int)(n); j++)
          if (ter[j]) {
            int u = a[j].cy, v = a[j].pc;
            if (!v)
              cyc[u].push_back(j);
            else
              prm[u][v] = j;
          }
        for (int j = (int)(1); j <= (int)(n); j++)
          if (!ter[j] && liu[id[j]]) {
            int u = C[liu[id[j]]], v = P[liu[id[j]]];
            if (!v)
              cyc[u].push_back(j);
            else
              prm[u][v] = j;
          }
        for (int j = (int)(1); j <= (int)(n); j++)
          if (app[j]) {
            prm[j][0] = cyc[j][0];
          }
        for (int j = (int)(1); j <= (int)(n); j++)
          if (!ter[j] && !liu[id[j]]) {
            int u = a[j].cy, v = a[j].pc;
            if (u == -1 && v == -1) {
              u = cho;
              v = max(mx[cho], 1);
            } else if (u == -1) {
              u = cho;
            } else {
              v = max(mx[u], 1);
            }
            if (!v) {
              ans[j] = j;
              continue;
            }
            ans[j] = prm[u][v - 1];
          }
        for (int j = (int)(1); j <= (int)(n); j++)
          if (app[j]) {
            for (int k = (int)(1); k <= (int)(now[j]); k++)
              ans[prm[j][k]] = prm[j][k - 1];
            for (int k = 0; k < (int)cyc[j].size(); k += j) {
              for (int u = k; u < k + j - 1; u++)
                ans[cyc[j][u]] = cyc[j][u + 1];
              ans[cyc[j][k + j - 1]] = cyc[j][k];
            }
          }
        for (int j = (int)(1); j <= (int)(n); j++)
          if (!ans[j]) {
            int u = a[j].cy, v = a[j].pc;
            assert(u != -1 && v > 0);
            ans[j] = prm[u][v - 1];
          }
        for (int j = (int)(1); j <= (int)(n); j++) printf("%d ", ans[j]);
        puts("");
        return 0;
      }
    }
  puts("-1");
  return 0;
}