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 GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
struct edge {
  int u, v;
  int cap;
  edge(int _u, int _v, int cap) : u(_u), v(_v), cap(cap) {}
  int get(int t) { return t ^ u ^ v; }
};
struct dinic {
  const int inf = 1e9;
  int n, st, tar;
  vector<edge> edges;
  vector<vector<int>> adj;
  vector<int> lvl, from;
  inline int comp(int i) { return i ^ 1; }
  inline int par(int i, int edge_num) { return edges[edge_num].get(i); }
  void init(int _n) {
    n = _n;
    adj.assign(n, vector<int>(0));
    edges.clear();
  }
  void add(int u, int v, int cap) {
    adj[u].push_back(edges.size());
    edges.emplace_back(u, v, cap);
    adj[v].push_back(edges.size());
    edges.emplace_back(v, u, 0);
  }
  void bfs() {
    lvl.assign(n, -1);
    lvl[st] = 0;
    queue<int> q;
    q.push(st);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i : adj[u]) {
        if (lvl[par(u, i)] != -1 || edges[i].cap == 0) continue;
        lvl[par(u, i)] = lvl[u] + 1;
        q.push(par(u, i));
      }
    }
  }
  int dfs(int u, int mnflow) {
    if (u == tar) return mnflow;
    for (int& i = from[u]; i < adj[u].size(); i++) {
      int v = par(u, adj[u][i]);
      if (lvl[v] != lvl[u] + 1 || edges[adj[u][i]].cap == 0) continue;
      int ret = dfs(v, min(mnflow, edges[adj[u][i]].cap));
      if (ret == 0) continue;
      edges[adj[u][i]].cap -= ret;
      edges[comp(adj[u][i])].cap += ret;
      return ret;
    }
    return 0;
  }
  int maxflow(int _st, int _tar) {
    st = _st;
    tar = _tar;
    int flow = 0;
    while (1) {
      bfs();
      if (lvl[tar] == -1) break;
      from.assign(n, 0);
      while (int nf = dfs(st, inf)) {
        flow += nf;
      }
    }
    return flow;
  }
};
const int N = 304;
int n, pre[N], cyc[N], mx, ind, mxpre[N], cnt[N];
int pos[N][N], req, st, tar, apre[N], acyc[N], to, ans[N], mid;
pair<int, int> invpos[N * N];
vector<int> fin[N][N];
string s;
dinic fo;
int inp() {
  cin >> s;
  if (s[0] == '?')
    return -1;
  else {
    return stoi(s);
  }
}
bool once() {
  st = 0, tar = 1, req = 0;
  mid = 0;
  fill(mxpre, mxpre + n + 1, -1);
  fill(cnt, cnt + n + 1, 0);
  for (int i = 0; i < n; i++) {
    if (cyc[i] != -1 && pre[i] == 0) {
    } else {
      pos[0][i] = tar;
      mid = tar;
      invpos[tar++] = make_pair(i, 0);
    }
    if (cyc[i] != -1) {
      if (pre[i] == 0) cnt[cyc[i]]++;
      mxpre[cyc[i]] = max({0, pre[i], mxpre[cyc[i]]});
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= mxpre[i]; j++) {
      pos[i][j] = tar;
      invpos[tar++] = make_pair(j, i);
    }
  }
  fo.init(tar + 1);
  for (int i = 0; i < n; i++) {
    if (cyc[i] == -1 || pre[i] != 0) {
      fo.add(0, pos[0][i], 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (mxpre[i] == -1) continue;
    int j = i * (cnt[i] / i);
    if (j == 0 || j < cnt[i]) j += i;
    if (j > cnt[i]) fo.add(pos[i][0], tar, j - cnt[i]);
    req += j - cnt[i];
    for (int j = 1; j <= mxpre[i]; j++) {
      fo.add(pos[i][j], tar, 1);
    }
    req += mxpre[i];
  }
  if (req > n) return false;
  for (int i = 0; i < n; i++) {
    if (cyc[i] != -1 && pre[i] == 0) continue;
    if (cyc[i] != -1 && pre[i] != -1) {
      fo.add(pos[0][i], pos[cyc[i]][pre[i]], 1);
    } else if (cyc[i] != -1) {
      for (int j = 0; j <= mxpre[cyc[i]]; j++) {
        fo.add(pos[0][i], pos[cyc[i]][j], 1);
      }
    } else if (pre[i] != -1) {
      for (int j = 1; j <= n; j++) {
        if (pre[i] <= mxpre[j]) {
          fo.add(pos[0][i], pos[j][pre[i]], 1);
        }
      }
    } else {
      for (int j = mid + 1; j < tar; j++) {
        fo.add(pos[0][i], j, 1);
      }
    }
  }
  int fl = fo.maxflow(0, tar);
  if (fl != req) return false;
  for (int i = 0; i < n; i++) {
    if (cyc[i] != -1 && pre[i] == 0) {
      apre[i] = pre[i], acyc[i] = cyc[i];
      continue;
    }
    if (fo.edges[fo.adj[pos[0][i]][0]].cap) {
      for (int x : fo.adj[pos[0][i]]) {
        to = fo.par(pos[0][i], x);
        if (to == 0) continue;
        if (fo.edges[x].cap) continue;
        apre[i] = invpos[to].first;
        acyc[i] = invpos[to].second;
        break;
      }
    } else {
      apre[i] = -1;
      for (int x : fo.adj[pos[0][i]]) {
        to = fo.par(pos[0][i], x);
        if (to == 0) continue;
        if (invpos[to].first == 0) continue;
        apre[i] = invpos[to].first;
        acyc[i] = invpos[to].second;
        break;
      }
      if (apre[i] == -1) {
        if (pre[i] == -1 && cyc[i] == -1) {
          apre[i] = 0, acyc[i] = 1;
        } else if (pre[i] == -1) {
          apre[i] = 1, acyc[i] = cyc[i];
        } else if (pre[i] == 0) {
          apre[i] = 0, acyc[i] = 1;
        } else {
          return false;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    fin[acyc[i]][apre[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (fin[i][0].empty()) continue;
    int lst = 0;
    assert((int)fin[i][0].size() % i == 0);
    for (int j = 1; j < (int)fin[i][0].size(); j++) {
      if (j % i) {
        ans[fin[i][0][j - 1]] = fin[i][0][j];
      } else {
        ans[fin[i][0][j - 1]] = fin[i][0][lst];
        lst = j;
      }
    }
    ans[fin[i][0][(int)fin[i][0].size() - 1]] = fin[i][0][lst];
    for (int j = 1; j < n; j++) {
      if (fin[i][j].empty()) break;
      for (auto x : fin[i][j]) ans[x] = fin[i][j - 1][0];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] + 1 << " ";
  }
  cout << '\n';
  return true;
}
void solve() {
  cin >> n;
  mx = -1;
  ind = -1;
  for (int i = 0; i < n; i++) {
    pre[i] = inp();
    cyc[i] = inp();
    if (cyc[i] == -1 && pre[i] > mx) {
      mx = pre[i];
      ind = i;
    }
  }
  if (once()) return;
  if (ind != -1) {
    for (int i = 1; i <= n; i++) {
      cyc[ind] = i;
      if (once()) return;
    }
  }
  cout << -1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}