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 = 350;
int G[N][N], vis[N], tL[N], tR[N], md[N], sz[N], n, cnt, len[N], dis[N], mx,
    x[N], y[N], used[N];
vector<int> ve[N][N];
int dfs(int x) {
  for (int i = 1; i <= n; ++i)
    if (G[i][x] && !vis[i]) {
      vis[i] = 1;
      if (!tR[i] || dfs(tR[i])) {
        tR[i] = x;
        tL[x] = i;
        return 1;
      }
    }
  return 0;
}
int to[N];
vector<int> vec[N];
void chk(int t) {
  cnt = 0;
  memset(tL, 0, sizeof tL);
  memset(tR, 0, sizeof tR);
  memset(used, 0, sizeof used);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) ve[i][j].clear();
  for (int i = 1; i <= n; ++i)
    if (dis[i] >= 0 && len[i] >= 0) ve[len[i]][dis[i]].push_back(i);
  for (int i = 1; i <= n; ++i)
    if (md[i] != -1 || i == t) {
      int s = sz[i], d = md[i];
      if (i == t) d = max(d, mx);
      for (int j = 1; j <= s; ++j) {
        if (++cnt > n) return;
        x[cnt] = i;
        y[cnt] = 0;
        if (!ve[x[cnt]][y[cnt]].empty()) {
          int u = ve[x[cnt]][y[cnt]].back();
          used[u] = 1;
          ve[x[cnt]][y[cnt]].pop_back();
          --cnt;
        }
      }
      for (int j = 1; j <= d; ++j) {
        if (++cnt > n) return;
        x[cnt] = i;
        y[cnt] = j;
        if (!ve[x[cnt]][y[cnt]].empty()) {
          int u = ve[x[cnt]][y[cnt]].back();
          used[u] = 1;
          ve[x[cnt]][y[cnt]].pop_back();
          --cnt;
        }
      }
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= cnt; ++j)
      G[i][j] =
          (len[i] == x[j] || len[i] == -1) && (dis[i] == y[j] || dis[i] == -1);
  for (int i = 1; i <= cnt; ++i)
    if (!tL[i]) {
      memcpy(vis, used, sizeof vis);
      if (!dfs(i)) return;
    }
  for (int i = 1; i <= cnt; ++i)
    assert(len[tL[i]] == -1 || dis[tL[i]] == -1), len[tL[i]] = x[i],
                                                  dis[tL[i]] = y[i];
  for (int i = 1; i <= n; ++i)
    if (len[i] == -1) {
      if (dis[i] == 0 || dis[i] == -1)
        dis[i] = 0, len[i] = 1;
      else
        len[i] = t;
    } else if (dis[i] == -1)
      dis[i] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (len[i] == len[j] && dis[i] == dis[j] + 1) {
        to[i] = j;
        break;
      }
  for (int i = 1; i <= n; ++i)
    if (!dis[i]) {
      vec[len[i]].push_back(i);
      if ((int)vec[len[i]].size() == len[i]) {
        int lst = i;
        for (int j : vec[len[i]]) to[j] = lst, lst = j;
        vec[len[i]].clear();
      }
    }
  for (int i = 1; i <= n; ++i) assert(vec[i].empty());
  for (int i = 1; i <= n; ++i) cout << to[i] << " \n"[i == n];
  exit(0);
}
int getint() {
  string s;
  cin >> s;
  if (s == "?")
    return -1;
  else
    return atoi(s.c_str());
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(md, -1, sizeof md);
  for (int i = 1; i <= n; ++i) {
    dis[i] = getint();
    len[i] = getint();
    if (len[i] == -1)
      mx = max(mx, dis[i]);
    else {
      md[len[i]] = max(0, max(md[len[i]], dis[i]));
      if (!dis[i]) ++sz[len[i]];
    }
  }
  for (int i = 1; i <= n; ++i) sz[i] = max(i, (sz[i] + i - 1) / i * i);
  for (int i = 1; i <= n; ++i) chk(i);
  cout << -1 << '\n';
  return 0;
}