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 maxn = 2010, inf = 1e9;
struct poi {
  int too, cf, pre;
} e[maxn * 200];
int n, m, x, y, z, s, t, tot, ans, tott, mxprec, mxflow;
int cur[maxn], last[maxn], dist[maxn], h[maxn], prec[maxn], c[maxn],
    pos[maxn][maxn], nxt[maxn], cnt[maxn];
bool vis[maxn], exi[maxn];
vector<int> v[maxn];
inline void read(int &k) {
  k = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '?') {
      k = -1;
      return;
    }
    c = getchar();
  }
  while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
}
inline void add(int x, int y, int z) {
  e[++tot] = (poi){y, z, last[x]};
  last[x] = tot;
}
inline void ins(int x, int y, int z) {
  add(x, y, z);
  add(y, x, 0);
}
inline bool bfs(int s, int t) {
  for (int i = 0; i <= t; i++) dist[i] = -1, vis[i] = 0;
  vis[s] = 1;
  dist[s] = 0;
  int front = 0, rear = 1;
  h[1] = s;
  while (front != rear) {
    int now = h[++front];
    if (front == maxn - 1) front = -1;
    for (int i = last[now], too; i; i = e[i].pre)
      if (!vis[too = e[i].too] && e[i].cf) {
        dist[too] = dist[now] + 1;
        vis[too] = 1;
        h[++rear] = too;
        if (too == t) return 1;
        if (rear == maxn - 1) rear = -1;
      }
  }
  return 0;
}
inline int dfs(int x, int flow) {
  if (x == t || !flow) return flow;
  int f = 0;
  for (int &i = cur[x], too; i; i = e[i].pre)
    if (dist[too = e[i].too] == dist[x] + 1 && e[i].cf) {
      int tmp = dfs(too, min(flow - f, e[i].cf));
      e[i].cf -= tmp;
      e[i ^ 1].cf += tmp;
      f += tmp;
      if (f == flow) break;
    }
  return f;
}
inline void dinic(int s, int t) {
  while (bfs(s, t)) {
    memcpy(cur, last, sizeof(last));
    ans += dfs(s, inf);
  }
}
inline void print(int ans) {
  for (int i = 1; i <= n; i++)
    if (prec[i] == -1 || c[i] == -1) {
      int flag = 0;
      for (int j = last[i], too; j; j = e[j].pre)
        if ((j & 1) == 0 && e[j].cf == 0) {
          prec[i] = prec[too = e[j].too];
          c[i] = c[too];
          flag = 1;
          break;
        }
      if (!flag) {
        if ((prec[i] == -1 || prec[i] == 0) && c[i] == -1)
          prec[i] = 0, c[i] = 1;
        else if (prec[i] == -1 && c[i] != -1)
          prec[i] = 1;
        else
          c[i] = ans;
      }
    }
  for (int i = 1; i <= n; i++) {
    pos[prec[i]][c[i]] = i;
    if (!prec[i]) v[c[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++)
      nxt[v[i][j]] = v[i][(j / i) * i + (j + 1) % i];
  }
  for (int i = 1; i <= n; i++)
    if (!nxt[i]) nxt[i] = pos[prec[i] - 1][c[i]];
  for (int i = 1; i <= n; i++) printf("%d ", nxt[i]);
}
inline void inspoi(int pc, int cy) {
  if (pos[pc][cy]) return;
  pos[pc][cy] = 1;
  mxflow++;
  ins(++tott, t, 1);
  prec[tott] = pc;
  c[tott] = cy;
  for (int j = 1; j <= n; j++)
    if ((prec[j] == -1 && (c[j] == cy || c[j] == -1)) ||
        (prec[j] == pc && c[j] == -1))
      ins(j, tott, 1);
  if (pc == 0)
    cnt[cy]++;
  else
    inspoi(pc - 1, cy);
}
inline bool check(int p) {
  s = 0;
  tott = n;
  tot = 1;
  t = n * 3 + 1;
  mxflow = 0;
  memset(last, 0, sizeof(last));
  memset(cnt, 0, sizeof(cnt));
  memset(pos, 0, sizeof(pos));
  memset(exi, 0, sizeof(exi));
  for (int i = 1; i <= n; i++) exi[c[i]] = 1;
  for (int i = 1; i <= n; i++)
    if (prec[i] != -1 && c[i] != -1)
      pos[prec[i]][c[i]] = i, cnt[c[i]] += (!prec[i]);
  for (int i = 1; i <= n; i++)
    if (prec[i] == -1 || c[i] == -1) ins(s, i, 1);
  for (int i = 1; i <= n; i++)
    if (mxprec == prec[i] && prec[i] && c[i] == -1 && !pos[prec[i] - 1][p])
      inspoi(prec[i] - 1, p);
  for (int i = 1; i <= n; i++)
    if (prec[i] != -1 && c[i] != -1 && prec[i] && !pos[prec[i] - 1][c[i]])
      inspoi(prec[i] - 1, c[i]);
  for (int i = 1; i <= n; i++)
    if (cnt[i] % i || (exi[i] && !cnt[i])) {
      int rest = i - (cnt[i] % i);
      mxflow += rest;
      ins(++tott, t, rest);
      prec[tott] = 0;
      c[tott] = i;
      for (int j = 1; j <= n; j++)
        if ((c[j] == -1 && prec[j] == 0) ||
            ((c[j] == -1 || c[j] == i) && prec[j] == -1))
          ins(j, tott, 1);
    }
  ans = 0;
  dinic(s, t);
  return ans == mxflow;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(prec[i]);
    read(c[i]);
    if (c[i] == -1) mxprec = max(prec[i], mxprec);
  }
  for (int i = 1; i <= n; i++)
    if (check(i)) return print(i), 0;
  puts("-1");
}