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>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int MAXK = -1;
const int MAXN = 602;
const int MOD = 1;
int n;
int pc[MAXN];
int c[MAXN];
int nxt[MAXN];
void read(int &x) {
  string s;
  cin >> s;
  if (s == "?") {
    x = -1;
    return;
  }
  stringstream ss;
  ss << s;
  ss >> x;
}
vector<pair<int, int> > o;
bool eq(int x, int y) { return x == y || y == -1; }
vector<int> e[MAXN];
int mt[MAXN];
int vis[MAXN], tmr;
bool dfs(int v) {
  if (vis[v] == tmr) return 0;
  vis[v] = tmr;
  for (int to : e[v]) {
    if (mt[to] == -1) {
      mt[to] = v;
      return 1;
    }
  }
  for (int to : e[v]) {
    if (dfs(mt[to])) {
      mt[to] = v;
      return 1;
    }
  }
  return 0;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      read(pc[i]);
      read(c[i]);
      nxt[i] = -1;
    }
    map<int, map<int, vector<int> > > mp;
    for (int i = 0; i < n; i++) {
      mp[c[i]][pc[i]].push_back(i);
    }
    bool ok = 0;
    int nmx = 0;
    if (mp.count(-1)) {
      nmx = max(0, mp[-1].rbegin()->first);
    }
    vector<int> mx(n + 1, -1);
    for (int i = 1; i <= n; i++) {
      if (!mp.count(i)) continue;
      mx[i] = mp[i].rbegin()->first;
    }
    for (int nc = 1; nc <= n; nc++) {
      bool wasnt = !mp.count(nc);
      mp[nc];
      int old = mx[nc];
      mx[nc] = max(mx[nc], nmx);
      o.clear();
      for (int cc = 1; cc <= n; cc++) {
        if (!mp.count(cc)) continue;
        vector<int> vct = mp[cc][0];
        vector<int> vv;
        vector<vector<int> > cycles;
        for (int x : vct) {
          if (vv.size() == cc) {
            for (int i = 0; i < (int)vv.size(); i++)
              nxt[vv[i]] = vv[(i + 1) % vv.size()];
            cycles.push_back(vv);
            vv.clear();
          }
          vv.push_back(x);
        }
        for (int i = 0; i < cc - (int)vv.size(); i++) {
          o.push_back(make_pair(0, cc));
        }
        for (int i = 1; i <= mx[cc]; i++) {
          if (!mp[cc].count(i)) {
            o.push_back(make_pair(i, cc));
          }
        }
      }
      int m = o.size();
      for (int i = 0; i < m; i++) {
        e[i].clear();
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if ((pc[i] == -1 || c[i] == -1) && eq(o[j].first, pc[i]) &&
              eq(o[j].second, c[i])) {
            e[j].push_back(i);
          }
        }
      }
      for (int i = 0; i < n; i++) {
        mt[i] = -1;
      }
      bool cok = 1;
      for (int i = 0; cok && i < m; i++) {
        tmr++;
        cok &= dfs(i);
      }
      if (cok) {
        for (int i = 0; i < n; i++) {
          if (mt[i] != -1) {
            pc[i] = o[mt[i]].first;
            c[i] = o[mt[i]].second;
          }
        }
        ok = 1;
        break;
      }
      mx[nc] = old;
      if (wasnt) mp.erase(nc);
    }
    if (ok) {
      vector<vector<int> > vv(n + 1);
      for (int i = 0; i < n; i++) {
        if (nxt[i] == -1 && pc[i] == 0 && c[i] != -1) {
          vv[c[i]].push_back(i);
        }
      }
      for (int i = 0; i <= n; i++) {
        for (int j = 0; j < (int)vv[i].size(); j++) {
          nxt[vv[i][j]] = vv[i][(j + 1) % vv[i].size()];
        }
      }
      int mxc = 0;
      for (int i = 0; i <= n; i++)
        if (mx[i] > mx[mxc]) mxc = i;
      for (int i = 0; i < n; i++) {
        if (nxt[i] != -1) continue;
        if ((c[i] == -1 || c[i] == 1) && pc[i] == 0) {
          nxt[i] = i;
          continue;
        }
        if (pc[i] == -1) pc[i] = 1;
        if (c[i] == -1) {
          c[i] = mxc;
        }
        for (int j = 0; j < n; j++) {
          if (c[j] == c[i] && pc[j] + 1 == pc[i]) {
            nxt[i] = j;
            break;
          }
        }
        assert(nxt[i] != -1);
      }
      for (int i = 0; i < n; i++) cout << nxt[i] + 1 << " \n"[i + 1 == n];
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}