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;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "yes" : "no");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int read() {
  char ch = getchar();
  int x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar()) {
    if (ch == '?') return -1;
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x;
}
int dis[305], len[305], cnt[305], maxX[305], unMaxX;
int x[305], y[305], fa[305];
const int maxn = 305;
int edge[maxn][maxn];
int vis[maxn];
int cx[maxn], cy[maxn];
int nx, ny;
int line(int u) {
  for (int(v) = 1; (v) <= (int)(ny); (v)++) {
    if (edge[u][v] && !vis[v]) {
      vis[v] = 1;
      if (cy[v] == -1 || line(cy[v])) {
        cx[u] = v;
        cy[v] = u;
        return 1;
      }
    }
  }
  return 0;
}
bool ck(int L) {
  int cc = 0;
  for (int(len) = 1; (len) <= (int)(n); (len)++)
    if (maxX[len] != -1 || len == L) {
      int c = cnt[len], l = maxX[len];
      if (L == len) {
        l = max(l, unMaxX);
        c = max(c, len);
      }
      for (int(j) = 1; (j) <= (int)(c); (j)++) {
        if (++cc > n) return 0;
        x[cc] = len;
        y[cc] = 0;
      }
      for (int(j) = 1; (j) <= (int)(l); (j)++) {
        if (++cc > n) return 0;
        x[cc] = len;
        y[cc] = j;
      }
    }
  int ans = 0;
  memset(edge, 0, sizeof edge);
  memset(cx, 0xff, sizeof(cx));
  memset(cy, 0xff, sizeof(cy));
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (int(j) = 1; (j) <= (int)(cc); (j)++) {
      edge[i][j] =
          (len[i] == x[j] || len[i] == -1) && (dis[i] == y[j] || dis[i] == -1);
      if (len[i] == x[j] && dis[i] == y[j] && cx[i] == -1 && cy[j] == -1) {
        cx[i] = j;
        cy[j] = i;
        ++ans;
      }
    }
  nx = n;
  ny = cc;
  for (int i = 1; i <= n; i++) {
    if (cx[i] == -1) {
      memset(vis, 0, sizeof(vis));
      ans += line(i);
    }
  }
  return ans == cc;
}
void pp(int L) {
  for (int(i) = 1; (i) <= (int)(ny); (i)++) {
    int u = cy[i];
    dis[u] = y[i];
    len[u] = x[i];
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    if (len[i] == -1) {
      if (dis[i] <= 0) {
        len[i] = 1;
        dis[i] = 0;
      } else
        len[i] = L;
    } else if (dis[i] == -1) {
      dis[i] = 1;
    }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (int(j) = 1; (j) <= (int)(n); (j)++)
      if (len[i] == len[j]) {
        if (dis[i] == dis[j] + 1) {
          fa[i] = j;
          break;
        }
      }
  for (int(l) = 1; (l) <= (int)(n); (l)++) {
    vector<int> vp;
    for (int(i) = 1; (i) <= (int)(n); (i)++)
      if (dis[i] == 0 && len[i] == l) {
        vp.push_back(i);
        if (vp.size() == l) {
          for (int j = 0; j < l; j++) {
            fa[vp[j]] = vp[(j + 1) % l];
          }
          vp.clear();
        }
      }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) printf("%d ", fa[i]);
}
void fmain() {
  scanf("%d", &n);
  memset(maxX, -1, sizeof maxX);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    dis[i] = read();
    len[i] = read();
    if (len[i] != -1) {
      if (dis[i] == 0) cnt[len[i]]++;
      maxX[len[i]] = max(maxX[len[i]], max(dis[i], 0));
    } else {
      unMaxX = max(unMaxX, dis[i]);
    }
  }
  for (int len = 1; len <= n; len++) {
    for (int j = len;; j += len) {
      if (cnt[len] <= j) {
        cnt[len] = j;
        break;
      }
    }
  }
  for (int(len) = 1; (len) <= (int)(n); (len)++)
    if (ck(len)) {
      pp(len);
      return;
    }
  et();
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain();
  }
  return 0;
}