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 M = 305, N = M << 1, inf = 1 << 30;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
};
int to[N * N], nt[N * N], c[N * N], hd[N], tot = 1;
void add(int x, int y, int z) {
  ++tot, to[tot] = y, nt[tot] = hd[x], c[tot] = z, hd[x] = tot;
  ++tot, to[tot] = x, nt[tot] = hd[y], c[tot] = 0, hd[y] = tot;
}
int ps, pt, nhd[N], lv[N];
bool bfs() {
  queue<int> q;
  for (int i = 1; i <= pt; ++i) lv[i] = 0;
  lv[ps] = 1, q.push(ps);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = hd[x]; i; i = nt[i]) {
      int y = to[i];
      if (c[i] > 0 && !lv[y]) lv[y] = lv[x] + 1, q.push(y);
    }
  }
  return lv[pt];
}
int dfs(int x, int fw) {
  if (x == pt) return fw;
  int an = 0;
  for (int &i = nhd[x]; i; i = nt[i]) {
    int y = to[i];
    if (c[i] > 0 && lv[y] == lv[x] + 1) {
      int dt = dfs(y, min(fw, c[i]));
      c[i] -= dt, c[i ^ 1] += dt;
      fw -= dt, an += dt;
      if (!fw) break;
    }
  }
  return an;
}
int dinic() {
  int an = 0, dt;
  while (bfs()) {
    memcpy(nhd, hd, sizeof(int) * (pt + 1));
    while ((dt = dfs(ps, inf))) an += dt;
  }
  return an;
}
char cc[5];
int n, m, mat[N], a[N], b[N], cn[M], t[M], an[M], ff[M][M];
bool v[M], vv[M];
vector<int> cr[M];
bool ck() {
  for (int j = 1; j <= n; ++j) v[j] = 0, cn[j] = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 1; j <= n; ++j) ff[i][j] = 0;
  for (int i = 1; i <= n; ++i) {
    if ((~a[i]) && (~b[i])) {
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
      if (!a[i]) ++cn[b[i]];
    }
    if (~b[i]) v[b[i]] = 1;
  }
  m = n;
  for (int i = 1; i <= n; ++i) {
    if (!v[i]) {
      t[i] = -1;
      continue;
    }
    int nm = (i - cn[i] % i) % i;
    while (nm--) a[++m] = 0, b[m] = i;
    int w = n + 1;
    while (w && !ff[w][i]) --w;
    t[i] = w;
    while (~w) {
      if (!ff[w][i]) {
        int T = w ? 1 : i;
        while (T--) a[++m] = w, b[m] = i;
      }
      --w;
    }
  }
  if (m > n + n) return 0;
  pt = m + 1;
  memset(hd, 0, sizeof(int) * (pt + 1)), tot = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] < 0 || b[i] < 0) {
      for (int j = n + 1; j <= m; ++j)
        if ((a[i] < 0 || a[i] == a[j]) && (b[i] < 0 || b[i] == b[j]))
          add(i, j, 1);
    }
  for (int i = 1; i <= n; ++i) add(ps, i, 1);
  for (int j = n + 1; j <= m; ++j) add(j, pt, 1);
  return dinic() >= m - n;
}
int main() {
  n = rd();
  int ii = -1, mx = -1;
  bool tg = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", cc);
    if (cc[0] == '?')
      a[i] = -1;
    else {
      int len = strlen(cc);
      for (int j = 0; j < len; ++j) a[i] = a[i] * 10 + cc[j] - 48;
    }
    scanf("%s", cc);
    if (cc[0] == '?')
      b[i] = -1;
    else {
      int len = strlen(cc);
      for (int j = 0; j < len; ++j) b[i] = b[i] * 10 + cc[j] - 48;
    }
    if (a[i] >= 0 && b[i] < 0 && a[i] > mx) mx = a[i], ii = i;
    if (b[i] > 0) tg = 1, vv[b[i]] = 1;
  }
  if (~ii) {
    if (!tg)
      for (int i = 1; i <= n; ++i) vv[i] = 1;
    bool ok = 0;
    for (int i = 1; !ok && i <= n; ++i) {
      if (!vv[i]) continue;
      b[ii] = i;
      ok = ck();
    }
    if (!ok) {
      puts("-1");
      return 0;
    }
  } else {
    if (!ck()) {
      puts("-1");
      return 0;
    }
  }
  for (int j = n + 1; j <= m; ++j) {
    for (int i = hd[j]; i; i = nt[i]) {
      int x = to[i];
      if (x <= n && c[i]) {
        a[x] = a[j], b[x] = b[j];
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if ((~a[i]) && (~b[i]))
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
  for (int i = 1; i <= n; ++i) {
    t[i] = n + 1;
    while (~t[i] && !ff[t[i]][i]) --t[i];
  }
  int jj = 1;
  for (int j = 2; j <= n; ++j)
    if (t[jj] < t[j]) jj = j;
  for (int i = 1; i <= n; ++i) {
    if ((a[i] < 0) ^ (b[i] < 0)) {
      if (a[i] < 0)
        a[i] = 1;
      else
        b[i] = a[i] ? jj : 1;
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] < 0 && b[i] < 0) {
      if (a[i] < 0) a[i] = 0, b[i] = 1;
      if (!ff[a[i]][b[i]]) ff[a[i]][b[i]] = i;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!a[i]) {
      cr[b[i]].push_back(i);
      if ((int)cr[b[i]].size() == b[i]) {
        for (int j = 0; j < b[i] - 1; ++j) an[cr[b[i]][j]] = cr[b[i]][j + 1];
        an[cr[b[i]][b[i] - 1]] = cr[b[i]][0];
        cr[b[i]].clear();
      }
    }
  for (int i = 1; i <= n; ++i)
    if (!cr[i].empty()) {
      puts("-1");
      return 0;
    }
  for (int i = 1; i <= n; ++i)
    printf("%d ", an[i] ? an[i] : ff[a[i] - 1][b[i]]);
  return 0;
}