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 = 310;
int n, m;
int cyc[N], prcyc[N], fa[N];
int x[N], y[N];
int cnt[N], maxlen[N];
int maxl;
int g[N][N], flg[N], ll[N], rr[N], rx[N];
vector<int> lst[N];
int dfs(int u) {
  for (int i = 1; i <= m; i++)
    if (g[u][i] && !flg[i] && !rr[i]) {
      flg[i] = 1;
      if (!rx[i] || dfs(rx[i])) return rx[i] = u, 1;
    }
  return 0;
}
bool check(int p) {
  memset(g, 0, sizeof(g));
  memset(ll, 0, sizeof(ll));
  memset(rr, 0, sizeof(rr));
  memset(rx, 0, sizeof(rx));
  m = 0;
  for (int i = 1; i <= n; i++)
    if (~maxlen[i] || i == p) {
      int c = cnt[i], pc = maxlen[i];
      if (i == p) c = max(c, i), pc = max(pc, maxl);
      for (int j = 1; j <= c; j++) {
        if (++m > n) return false;
        x[m] = i;
        y[m] = 0;
      }
      for (int j = 1; j <= pc; j++) {
        if (++m > n) return false;
        x[m] = i;
        y[m] = j;
      }
    }
  int res = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      g[i][j] = (cyc[i] == x[j] || cyc[i] == -1) &&
                (prcyc[i] == y[j] || prcyc[i] == -1);
      if (cyc[i] == x[j] && prcyc[i] == y[j] && !ll[i] && !rr[j]) {
        ll[i] = rr[j] = 1;
        rx[j] = i;
        res++;
      }
    }
  for (int i = 1; i <= n; i++)
    if (!ll[i]) memset(flg, 0, sizeof(flg)), res += dfs(i);
  return res == m;
}
void print_sol(int p) {
  for (int i = 1; i <= m; i++) cyc[rx[i]] = x[i], prcyc[rx[i]] = y[i];
  for (int i = 1; i <= n; i++)
    if (cyc[i] == -1) {
      if (prcyc[i] <= 0)
        prcyc[i] = 0, cyc[i] = 1;
      else
        cyc[i] = p;
    } else if (prcyc[i] == -1)
      prcyc[i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (cyc[i] == cyc[j] && prcyc[i] == prcyc[j] + 1) {
        fa[i] = j;
        break;
      }
  for (int i = 1; i <= n; i++)
    if (prcyc[i] == 0) {
      lst[cyc[i]].push_back(i);
      if (lst[cyc[i]].size() == cyc[i]) {
        for (int j = 0; j < cyc[i]; j++)
          fa[lst[cyc[i]][j]] = lst[cyc[i]][(j + 1) % cyc[i]];
        lst[cyc[i]].clear();
      }
    }
  for (int i = 1; i <= n; i++) printf("%d ", fa[i]);
  puts("");
}
int main() {
  scanf("%d", &n);
  memset(maxlen, 0xff, sizeof(maxlen));
  for (int i = 1; i <= n; i++) {
    char st1[5], st2[5];
    scanf("%s%s", st1, st2);
    prcyc[i] = st1[0] == '?' ? -1 : atoi(st1);
    cyc[i] = st2[0] == '?' ? -1 : atoi(st2);
    if (cyc[i] != -1) {
      maxlen[cyc[i]] = max(maxlen[cyc[i]], max(prcyc[i], 0));
      if (!prcyc[i]) cnt[cyc[i]]++;
    } else
      maxl = max(maxl, prcyc[i]);
  }
  for (int i = 1; i <= n; i++) cnt[i] = max(1, (cnt[i] + i - 1) / i) * i;
  for (int i = 1; i <= n; i++)
    if (check(i)) {
      print_sol(i);
      return 0;
    }
  puts("-1");
  return 0;
}