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 State {
  int p, c, id;
  bool operator<(const State& b) const {
    if (c != b.c) return c < b.c;
    return p < b.p;
  }
} have[333], need[333];
int N;
int ncou, hcou;
int rem[333][333];
int csum[333], cmax[333];
int maxn, rmax;
State use[333];
int ucou;
inline void addNeed(int a, int b) {
  ++ncou;
  need[ncou].p = a;
  need[ncou].c = b;
}
inline void solve(int C) {
  int x = (C - rem[0][C] % C) % C;
  if (rem[0][C] == 0) x = C;
  while (x--) addNeed(0, C);
  for (int i = 1; i <= cmax[C]; ++i)
    if (rem[i][C] == 0) addNeed(i, C);
  if (cmax[C] > maxn) {
    maxn = cmax[C];
    rmax = C;
  }
}
bool vis[333];
int linker[333];
int uN, vN;
int line[333][333];
bool find(int u) {
  for (int v = 1; v <= vN; ++v)
    if (line[u][v] && !vis[v]) {
      vis[v] = 1;
      if (linker[v] == -1 || find(linker[v])) {
        linker[v] = u;
        return 1;
      }
    }
  return 0;
}
int Hungary() {
  int ret = 0;
  for (int u = 1; u <= uN; ++u) {
    memset(vis, 0, sizeof(vis));
    if (find(u)) ++ret;
  }
  return ret;
}
bool judge() {
  uN = ncou;
  vN = hcou;
  for (int i = 1; i <= vN; ++i) {
    linker[i] = -1;
    for (int j = 1; j <= uN; ++j) line[j][i] = 0;
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= uN; ++i)
    for (int j = 1; j <= vN; ++j)
      if ((have[j].p == N + 1 || have[j].p == need[i].p) &&
          (have[j].c == N + 1 || have[j].c == need[i].c))
        line[i][j] = 1;
  if (Hungary() < uN) return 0;
  for (int i = 1; i <= vN; ++i)
    if (linker[i] != -1) {
      use[++ucou] = need[linker[i]];
      use[ucou].id = have[i].id;
    }
  return 1;
}
int ans[333];
int rans[333][333];
int bP[333], bC[333];
inline void getans(int L, int R) {
  int C = use[L].c;
  int last = L;
  int start;
  rans[0][C] = use[L].id;
  for (int i = L, j = 1; i <= R && use[i].p == 0; ++i, ++j) {
    ans[use[i].id] = use[i - 1].id;
    if (j % C == 0) {
      ans[use[last].id] = use[i].id;
      last = i + 1;
    }
    start = i;
  }
  ++start;
  last = use[L].id;
  for (int i = start; i <= R; ++i)
    if (i == start || use[i].p == use[i - 1].p) {
      ans[use[i].id] = last;
      rans[use[i].p][C] = last;
    } else {
      last = use[i - 1].id;
      ans[use[i].id] = last;
      rans[use[i].p][C] = last;
    }
  last = use[R].id;
  rans[use[R].p + 1][C] = last;
}
inline void getans() {
  memset(ans, -1, sizeof(ans));
  memset(rans, 0, sizeof(rans));
  sort(use + 1, use + ucou + 1);
  use[ucou + 1].c = -1;
  int last = 1;
  for (int i = 2; i <= ucou + 1; ++i)
    if (use[i].c != use[i - 1].c) {
      getans(last, i - 1);
      last = i;
    }
  for (int i = 1; i <= N; ++i) {
    if (ans[i] == -1) {
      if (bP[i] == N + 1 && bC[i] == N + 1)
        ans[i] = i;
      else if (bP[i] != N + 1) {
        if (bP[i])
          ans[i] = rans[bP[i]][rmax];
        else
          ans[i] = i;
      } else
        ans[i] = rans[1][bC[i]];
    }
    printf("%d ", ans[i]);
  }
  puts("");
}
State tuse[333];
int main() {
  char s1[100], s2[100];
  int a, b;
  int tttsum = 0;
  memset(cmax, -1, sizeof(cmax));
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%s %s", s1, s2);
    if (s1[0] == '?')
      a = N + 1;
    else
      sscanf(s1, "%d", &a);
    if (s2[0] == '?')
      b = N + 1;
    else
      sscanf(s2, "%d", &b);
    bP[i] = a;
    bC[i] = b;
    if (a == N + 1 || b == N + 1) {
      ++hcou;
      have[hcou].p = a;
      have[hcou].c = b;
      have[hcou].id = i;
      if (a != N + 1 || b != N + 1) ++tttsum;
    } else {
      ++ucou;
      use[ucou].p = a;
      use[ucou].c = b;
      use[ucou].id = i;
    }
    ++rem[a][b];
    ++csum[b];
    if (a != N + 1) cmax[b] = max(cmax[b], a);
  }
  maxn = -1;
  for (int i = 1; i <= N; ++i)
    if (csum[i]) solve(i);
  int tncou = ncou;
  int tucou = ucou;
  for (int i = 1; i <= ucou; ++i) tuse[i] = use[i];
  for (int i = 1; i <= N; ++i)
    if (i == 1 || csum[i]) {
      ncou = tncou;
      ucou = tucou;
      for (int j = 1; j <= ucou; ++j) use[j] = tuse[j];
      if (i == 1 && csum[1] == 0) addNeed(0, 1);
      rmax = i;
      if (cmax[N + 1] > cmax[i])
        for (int j = max(1, cmax[i] + 1); j <= cmax[N + 1]; ++j)
          addNeed(j, rmax);
      if (judge()) {
        getans();
        return 0;
      }
    }
  puts("-1");
  return 0;
}