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
#include <bits/stdc++.h>
int gi() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '?') return -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
bool eq(int a, int b) {
  if (b == -1) return 1;
  return a == b;
}
int n, D[310], L[310], Cnt[310], CNT[310], exist[310], maxdep[310];
int p[310];
int fir[610], dep[610], head[610], dis[10000010], nxt[10000010], w[10000010],
    id, cnt;
int S, T, numl[310], numr[310], chain[310][310], chlen[310];
void link(int a, int b, int c) {
  nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c;
  nxt[++id] = fir[b], fir[b] = id, dis[id] = a, w[id] = 0;
}
int edger[310], edgelr[310][310], edgelc[310][310][310];
bool BFS() {
  static int que[610], hd, tl;
  hd = tl = 0;
  que[tl++] = S;
  memset(dep, 0, sizeof dep);
  dep[S] = 1;
  while (hd ^ tl) {
    int x = que[hd++];
    for (int i = fir[x]; i; i = nxt[i])
      if (w[i] && !dep[dis[i]]) dep[dis[i]] = dep[x] + 1, que[tl++] = dis[i];
  }
  return dep[T];
}
int Dinic(int x, int maxflow) {
  if (x == T) return maxflow;
  int ret = 0;
  for (int& i = head[x]; i; i = nxt[i])
    if (dep[dis[i]] == dep[x] + 1 && w[i]) {
      int d = Dinic(dis[i], std::min(w[i], maxflow - ret));
      w[i] -= d, w[i ^ 1] += d;
      ret += d;
      if (ret == maxflow) break;
    }
  return ret;
}
std::vector<int> V[310][310];
int Get(int i, int j) {
  int r = V[i][j].back();
  V[i][j].pop_back();
  return r;
}
int main() {
  n = gi();
  int maxl = 0;
  for (int i = 1; i <= n; ++i) {
    D[i] = gi(), L[i] = gi();
    if (~L[i]) {
      if (~D[i]) maxdep[L[i]] = std::max(maxdep[L[i]], D[i]);
      if (D[i] == 0)
        ++Cnt[L[i]];
      else
        exist[L[i]] = 1;
    } else
      maxl = std::max(maxl, D[i]);
  }
  for (int i = 1; i <= n; ++i) {
    CNT[i] = (Cnt[i] + i - 1) / i;
    if (exist[i]) CNT[i] = std::max(CNT[i], 1);
  }
  bool FLG = 0;
  for (int o = 1; o <= n; ++o) {
    cnt = 2;
    S = 1, T = 2;
    memset(fir, 0, sizeof fir);
    id = 1;
    int tot = 0;
    bool flg = !CNT[o];
    if (flg)
      if (!FLG)
        FLG = 1, CNT[o] = 1;
      else
        continue;
    for (int i = 1; i <= n; ++i) {
      int c = CNT[i] * i - Cnt[i];
      if (c)
        edger[i] = id + 1, link(numr[i] = ++cnt, T, c), tot += c;
      else
        edger[i] = -1;
    }
    int sum = tot;
    for (int i = 1; i <= n; ++i) {
      chlen[i] = std::max(o == i ? maxl : 0, maxdep[i]);
      sum += chlen[i];
    }
    if (sum > n) {
      if (flg) CNT[o] = 0;
      continue;
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= chlen[i]; ++j)
        link(chain[i][j] = ++cnt, T, 1), ++tot;
    }
    for (int i = 1; i <= n; ++i) {
      memset(edgelr[i], -1, sizeof edgelr[i]);
      memset(edgelc[i], -1, sizeof edgelc[i]);
      if (D[i] == 0 && ~L[i]) continue;
      link(S, numl[i] = ++cnt, 1);
      if (D[i] <= 0)
        for (int j = 1; j <= n; ++j)
          if (numr[j] && eq(j, L[i]))
            edgelr[i][j] = id + 1, link(numl[i], numr[j], 1);
      if (D[i] != 0) {
        for (int j = 1; j <= n; ++j)
          if (eq(j, L[i]))
            for (int k = 1; k <= chlen[j]; ++k)
              if (k == D[i] || D[i] == -1)
                edgelc[i][j][k] = id + 1, link(numl[i], chain[j][k], 1);
      }
    }
    while (BFS()) memcpy(head, fir, sizeof head), tot -= Dinic(S, 1e9);
    if (tot) {
      if (flg) CNT[o] = 0;
      continue;
    }
    for (int i = 1; i <= n; ++i) p[i] = -1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j)
        if (~edgelr[i][j] && !w[edgelr[i][j]]) L[i] = j, D[i] = 0;
      for (int j = 1; j <= n; ++j)
        for (int k = 1; k <= chlen[j]; ++k)
          if (~edgelc[i][j][k] && !w[edgelc[i][j][k]]) L[i] = j, D[i] = k;
      if (~L[i] && ~D[i]) V[D[i]][L[i]].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
      if (!CNT[i]) continue;
      static int seq[82];
      while (CNT[i]--) {
        for (int j = 1; j <= i; ++j) seq[j] = Get(0, i);
        seq[0] = seq[i];
        for (int j = 1; j <= i; ++j) p[seq[j - 1]] = seq[j];
      }
      for (int j = 1; j <= chlen[i]; ++j) seq[j] = Get(j, i);
      for (int j = 1; j <= chlen[i]; ++j) p[seq[j]] = seq[j - 1];
      for (int j = 1; j <= n; ++j)
        if (p[j] == -1 && D[j] && eq(i, L[j]) && chlen[i] >= D[j] - 1)
          p[j] = seq[std::max(0, D[j] - 1)];
    }
    for (int i = 1; i <= n; ++i) printf("%d ", ~p[i] ? p[i] : i);
    exit(0);
  }
  puts("-1");
  return 0;
}
