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;
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return b < a ? a : b;
}
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0, b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
inline int tc() {
  int c = fetch();
  while (c <= 32 && c != EOF) c = fetch();
  return c;
}
inline int tyc() {
  int a = 0, b = 1, c = tc();
  if (c == '-')
    b = 0;
  else if (!isdigit(c))
    return -2e9;
  else
    while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
}  // namespace ae86
using ae86::tc;
using ae86::ty;
using ae86::tyc;
const int _ = 307, _n = 999, _e = 9999999, inf = 0x3f3f3f3f;
struct netflow {
  int to[_e], ne[_e], ev[_e], he[_n], ecnt;
  void adde(int a, int b, int c) {
    to[++ecnt] = b, ev[ecnt] = c, ne[ecnt] = he[a], he[a] = ecnt;
  }
  void addde(int a, int b, int c) { adde(a, b, c), adde(b, a, 0); }
  int S, T, dis[_n], gap[_n], dcnt;
  int dfs(int x, int f) {
    if (x == T || !f) return f;
    int r = f, mid = dcnt - 1;
    for (int i = he[x]; i; i = ne[i]) {
      if (ev[i] <= 0) continue;
      int b = to[i];
      if (dis[b] + 1 == dis[x]) {
        int g = dfs(b, min(r, ev[i]));
        r -= g, ev[i] -= g, ev[i ^ 1] += g;
        if (dis[S] >= dcnt) return f - r;
        if (!r) break;
      }
      mid = min(mid, dis[b]);
    }
    if (f == r) {
      if (--gap[dis[x]] == 0) dis[S] = dcnt;
      dis[x] = mid + 1, gap[dis[x]]++;
    }
    return f - r;
  }
  int run(int s, int t) {
    S = s, T = t, memset(dis, 0, sizeof(dis)), memset(gap, 0, sizeof(gap)),
    gap[0] = dcnt;
    int sflw = 0;
    while (dis[S] < dcnt) sflw += dfs(S, inf);
    return sflw;
  }
  void cls() {
    for (int i = 0; i <= ecnt; i++) to[i] = ne[i] = ev[i] = 0;
    for (int i = 0; i <= dcnt; i++) he[i] = 0;
    dcnt = 0, ecnt = 1;
  }
  netflow() { memset(he, 0, sizeof(he)), ecnt = 1; }
} nf;
int n, tot, len, dis[_], dlen[_], pcnt[_][_] = {0}, pr[_] = {0};
int ed[_], got[_][_];
pair<int, int> pans[_n];
int able() {
  nf.cls(), tot = n, len = -1, memset(ed, 0, sizeof(ed)),
            memset(got, 0, sizeof(got));
  for (int i = 1; i <= n; i++) ed[dlen[i]] = 1;
  int tar = 0;
  for (int i = 1; i <= n; i++) {
    if (!ed[i]) continue;
    int x = 0;
    if (!pcnt[i][0])
      x = i;
    else
      x = i - (pcnt[i][0] - 1) % i - 1;
    if (x)
      got[i][0] = ++tot, pans[tot] = make_pair(i, 0), nf.addde(0, tot, x),
      tar += x;
    for (int j = 1; j < pr[i]; j++)
      if (!pcnt[i][j])
        got[i][j] = ++tot, pans[tot] = make_pair(i, j), nf.addde(0, tot, 1),
        tar++;
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] <= n && dlen[i] <= n) continue;
    if (dis[i] > n && dlen[i] > n)
      for (int j = n + 1; j <= tot; j++) nf.addde(j, i, 1);
    else if (dis[i] > n) {
      for (int j = 0; j < pr[dlen[i]]; j++)
        if (got[dlen[i]][j]) nf.addde(got[dlen[i]][j], i, 1);
    } else if (dlen[i] > n) {
      for (int j = 1; j <= n; j++)
        if (got[j][dis[i]]) nf.addde(got[j][dis[i]], i, 1);
    }
    nf.addde(i, tot + 1, 1);
  }
  tot++, nf.dcnt = tot + 1;
  return nf.run(0, tot) >= tar;
}
int ans[_];
vector<int> temp[_][_];
int mxloc;
int main() {
  mxloc = 0, memset(pcnt, 0, sizeof(pcnt)), memset(pr, 0, sizeof(pr));
  n = ty();
  for (int i = 1; i <= n; i++) {
    dis[i] = tyc(), dlen[i] = tyc();
    if (dis[i] < 0) dis[i] = n + 1;
    if (dlen[i] < 0) dlen[i] = n + 1;
    if (dis[i] <= n && dlen[i] > n) {
      if (dis[mxloc] < dis[i]) mxloc = i;
    } else
      pcnt[dlen[i]][dis[i]]++;
  }
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= 0; j--)
      if (pcnt[i][j]) {
        pr[i] = j;
        break;
      }
  int vict = 0;
  for (int i = 1; i <= n; i++) {
    int loc = pr[i];
    if (pr[i] < dis[mxloc]) pr[i] = dis[mxloc], dlen[mxloc] = i;
    if (able()) {
      vict = 1;
      break;
    }
    dlen[mxloc] = n + 1, pr[i] = loc;
  }
  if (!vict) {
    puts("-1");
    return 0;
  }
  for (int i = n + 1; i < tot; i++)
    for (int j = nf.he[i]; j; j = nf.ne[j]) {
      int b = nf.to[j];
      if (1 <= b && b <= n && !nf.ev[j])
        dlen[b] = pans[i].first, dis[b] = pans[i].second;
    }
  for (int i = 1; i <= n; i++) {
    if (dis[i] > n && dlen[i] > n)
      dis[i] = 0, dlen[i] = 1;
    else if (dis[i] > n)
      dis[i] = 1;
    else if (dlen[i] > n)
      for (int j = 1; j <= n; j++)
        if (pr[j] >= dis[i]) {
          dlen[i] = j;
          break;
        }
  }
  for (int i = 1; i <= n; i++) temp[dlen[i]][dis[i]].push_back(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 0, jj = temp[i][0].size(); j < jj; j += i) {
      for (int k = j; k < j + i - 1; k++)
        ans[temp[i][0][k]] = temp[i][0][k + 1];
      ans[temp[i][0][j + i - 1]] = temp[i][0][j];
    }
    for (int j = 1; j <= n; j++)
      for (int k = 0, kk = temp[i][j].size(); k < kk; k++)
        ans[temp[i][j][k]] = temp[i][j - 1][0];
  }
  for (int i = 1; i <= n; i++) printf("%d", ans[i]), putchar(" \n"[i == n]);
  return 0;
}