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 N = 307;
bool fl[N], fg[N];
vector<int> g[N][N];
int n, q, p[N], xz[N], yz[N], x[N], y[N], ft[N], fa[N], xa[N], ya[N], f1[N],
    f2[N], f3[N], op[N][N], cnt[N];
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g && g != '?') g = getchar();
  while (47 < g && g < 58 && g != '?')
    num = (num << 1) + (num << 3) + g - 48, g = getchar();
  if (g == '?')
    return -1;
  else
    return num;
}
inline bool check(int a, int b) {
  if (x[a] != -1 && x[a] != xa[b]) return 0;
  if (y[a] != -1 && y[a] != ya[b]) return 0;
  return 1;
}
inline bool check(int v) {
  for (int i = 1; i <= q; i++) {
    if (xa[i] == -1 && ya[i] == -1) continue;
    if (!fl[i] && check(v, i)) {
      fl[i] = 1;
      if (!ft[i] || check(ft[i])) {
        ft[i] = v;
        return 1;
      }
    }
  }
  return 0;
}
inline bool solve(int d) {
  for (int i = 1; i <= n; i++) x[i] = xz[i], y[i] = yz[i];
  q = 0, p[0] = 0, memset(ft, 0, sizeof(ft)), p[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (q + f2[i] + f3[i] > n) return 0;
    for (int j = 1; j <= f2[i]; j++) q++, xa[q] = i, ya[q] = 0;
    for (int j = 1; j <= f3[i]; j++) q++, xa[q] = i, ya[q] = j;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (x[i] == -1 && y[i] == -1) {
      sum++, p[++p[0]] = i;
      continue;
    }
    if (x[i] == -1 || y[i] == -1) continue;
    for (int j = 1; j <= q; j++)
      if (x[i] == xa[j] && y[i] == ya[j]) {
        xa[j] = -1, ya[j] = -1, sum++;
        break;
      }
  }
  for (int i = 1; i <= n; i++) {
    if (x[i] == -1 && y[i] == -1) continue;
    if (x[i] == -1 || y[i] == -1) {
      memset(fl, 0, sizeof(fl));
      if (check(i)) sum++;
    }
  }
  if (sum < q) return 0;
  for (int i = 1; i <= q; i++) {
    if (!ft[i] && xa[i] != -1 && ya[i] != -1) ft[i] = p[p[0]--];
    x[ft[i]] = xa[i], y[ft[i]] = ya[i];
  }
  for (int i = 1; i <= n; i++)
    if (x[i] == -1 && y[i] == 0) x[i] = 1;
  memset(fg, 0, sizeof(fg));
  for (int i = 1; i <= f3[d]; i++) fg[i] = 1;
  int s = 0, res = 0, ogt = 0;
  for (int i = 1; i <= n; i++)
    if (x[i] == -1 && y[i] >= 0) fg[y[i]] = 1, s = max(s, y[i]);
  for (int i = 1; i <= n; i++)
    if ((x[i] == d || x[i] == -1) && y[i] == -1) res++;
  while (fg[f3[d] + 1]) f3[d]++;
  for (int i = 1; i <= s; i++)
    if (fg[i]) ogt++;
  if (res + ogt < s) return 0;
  int og = 1;
  for (int i = 1; i <= n; i++)
    if (x[i] == -1 && y[i] >= 0) x[i] = d;
  for (int i = 1; i <= n; i++) {
    if ((x[i] == d || x[i] == -1) && y[i] == -1) {
      while (fg[og]) og++;
      x[i] = d, y[i] = og, fg[og] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    if (y[i] == -1 && x[i] != -1) f3[x[i]]++, y[i] = f3[x[i]];
  for (int i = 1; i <= n; i++) g[x[i]][y[i]].push_back(i);
  for (int i = 1; i <= n; i++)
    if (y[i] > 0)
      fa[i] = g[x[i]][y[i] - 1][0];
    else {
      op[x[i]][y[i]]++;
      int z = op[x[i]][y[i]];
      if (z % x[i] == 0)
        z = z - x[i] + 1;
      else
        z = z + 1;
      fa[i] = g[x[i]][y[i]][z - 1];
    }
  for (int i = 1; i <= n; i++) cout << fa[i] << " ";
  return 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) y[i] = read(), x[i] = read();
  bool ret = 0;
  for (int i = 1; i <= n; i++)
    if (x[i] >= 0) {
      f1[x[i]]++, cnt[x[i]]++, ret = 1;
      if (y[i] == 0)
        f2[x[i]]++;
      else
        f3[x[i]] = max(f3[x[i]], y[i]);
    }
  for (int i = 1; i <= n; i++) {
    f2[i] = f2[i] - (f2[i] % i) + ((f2[i] % i) > 0) * i;
    if (f1[i]) f2[i] = max(f2[i], i);
  }
  int s = 0;
  for (int i = 1; i <= n; i++)
    if (x[i] == -1) s = max(s, y[i]);
  if (!ret) f2[1] = 1, cnt[1] = 1;
  memcpy(xz, x, sizeof(xz)), memcpy(yz, y, sizeof(yz));
  for (int i = 1; i <= n; i++)
    if (cnt[i] && solve(i)) return 0;
  for (int i = 1; i <= n; i++) {
    int a = f2[i], b = f3[i];
    f3[i] = max(f3[i], s);
    f2[i] = max(f2[i], i);
    if (solve(i)) return 0;
    f2[i] = a, f3[i] = b;
  }
  cout << -1 << endl;
  return 0;
}