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 = 5e5 + 10;
int n, d[N], l[N], to[N], ww[N], nxt[N], tt = 1, h[N], cur[N], s, t, dep[N],
                                         cnt[N], x[N], y[N], len = 0, mx[N], md,
                                         p[N];
bool vis[N], vv[1010][1010];
void adde(int u, int v, int w) {
  to[++tt] = v, ww[tt] = w, nxt[tt] = h[u], h[u] = tt;
  to[++tt] = u, ww[tt] = 0, nxt[tt] = h[v], h[v] = tt;
}
bool bfs() {
  memset(dep, 0, 4 * (t + 1));
  queue<int> q;
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = h[u], v; v = to[i], i; i = nxt[i])
      if (!dep[v] && ww[i]) {
        dep[v] = dep[u] + 1;
        q.push(v);
        if (v == t) return 1;
      }
  }
  return 0;
}
int dfs(int u, int flow) {
  if (u == t) return flow;
  int ret = 0;
  for (int &i = cur[u], v; v = to[i], i; i = nxt[i])
    if (dep[v] == dep[u] + 1 && ww[i]) {
      int d = dfs(v, min(flow, ww[i]));
      ww[i] -= d, ww[i ^ 1] += d, ret += d, flow -= d;
      if (!flow) return ret;
    }
  dep[u] = 0;
  return ret;
}
int dinic() {
  int ret = 0;
  while (bfs()) {
    memcpy(cur, h, 4 * (t + 1));
    ret += dfs(s, 1e9);
  }
  return ret;
}
int get() {
  string s;
  cin >> s;
  if (s == "?") return -1;
  return atoi(s.c_str());
}
vector<int> vec[N];
bool cmp(int x, int y) { return d[x] < d[y]; }
void build_cyc(vector<int> a) {
  for (int i = 0; i < int(a.size()) - 1; i++) p[a[i]] = a[i + 1];
  p[a.back()] = a[0];
}
void build() {
  for (int i = 1; i <= n; i++) vec[l[i]].push_back(i);
  for (int i = 1; i <= n; i++)
    if (!vec[i].empty()) {
      sort(vec[i].begin(), vec[i].end(), cmp);
      int lst;
      while (!vec[i].empty() && d[vec[i][0]] == 0) {
        vector<int> cyc;
        for (int j = 1; j <= i; j++)
          cyc.push_back(lst = vec[i][0]), vec[i].erase(vec[i].begin());
        build_cyc(cyc);
      }
      for (int j = 0; j < int(vec[i].size()); j++) {
        if (j && d[vec[i][j]] != d[vec[i][j - 1]]) lst = vec[i][j - 1];
        p[vec[i][j]] = lst;
      }
    }
  for (int i = 1; i <= n; i++) cout << p[i] << ' ';
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    d[i] = get(), l[i] = get();
    if (~l[i]) {
      vis[l[i]] = 1;
      if (d[i] == 0) ++cnt[l[i]];
      if (~d[i]) vv[d[i]][l[i]] = 1;
      mx[l[i]] = max(mx[l[i]], d[i]);
    }
    if (!~l[i]) md = max(md, d[i]);
  }
  for (int a = 1; a <= n; a++) {
    bool _vis = vis[a], _vv = vv[md][a];
    int _mx = mx[a];
    if (md) vis[a] = 1, mx[a] = max(mx[a], md), vv[md][a] = 1;
    len = 0;
    for (int i = 1; i <= n; i++)
      if (vis[i]) {
        int need = max(1, (cnt[i] - 1) / i + 1) * i;
        for (int j = 1; j <= need - cnt[i]; j++) x[++len] = 0, y[len] = i;
        for (int j = 1; j <= mx[i]; j++)
          if (!vv[j][i]) x[++len] = j, y[len] = i;
      }
    bool fl = 0;
    t = n + len + 1;
    tt = 1;
    memset(h, 0, 4 * (t + 1));
    for (int i = 1; i <= n; i++) {
      if (~l[i] && ~d[i]) continue;
      if (md && d[i] == md && !fl) {
        fl = 1;
        continue;
      }
      adde(s, i, 1);
      for (int j = 1; j <= len; j++)
        if ((d[i] == -1 || d[i] == x[j]) && (l[i] == -1 || l[i] == y[j]))
          adde(i, j + n, 1);
    }
    for (int i = 1; i <= len; i++) adde(i + n, t, 1);
    if (dinic() == len) {
      for (int u = 1; u <= n; u++)
        for (int i = h[u], v; v = to[i], i; i = nxt[i])
          if (!ww[i] && n + 1 <= v && v <= n + len) {
            d[u] = x[v - n];
            l[u] = y[v - n];
            break;
          }
      bool fl = 0;
      for (int i = 1; i <= n; i++) {
        if (~l[i] && ~d[i]) continue;
        if (md && d[i] == md && !fl) {
          fl = 1;
          l[i] = a;
        } else {
          if (!~l[i] && !~d[i])
            l[i] = 1, d[i] = 0;
          else if (~l[i])
            d[i] = 1;
          else if (d[i] == 0)
            l[i] = 1;
          else
            l[i] = a;
        }
      }
      build();
      return 0;
    }
    vis[a] = _vis, mx[a] = _mx, vv[md][a] = _vv;
  }
  cout << "-1";
  return 0;
}