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;
bool augmentDFS(const int u, const vector<vector<int>> &adj,
                vector<bool> &visited, vector<int> &match) {
  if (u == -1) return 1;
  if (visited[u]) return 0;
  visited[u] = true;
  for (auto &&v : adj[u])
    if (augmentDFS(match[v], adj, visited, match)) {
      match[u] = v;
      match[v] = u;
      return true;
    }
  return false;
}
pair<int, vector<int>> maxMatching(const int n, const int m,
                                   const vector<vector<int>> &adj) {
  vector<bool> visited(n);
  vector<int> match(n + m, -1);
  int res = 0;
  for (int i = 0; i < n; ++i) {
    fill(visited.begin(), visited.end(), 0);
    res += augmentDFS(i, adj, visited, match);
  }
  return {res, match};
}
map<pair<int, int>, int> getNeed(const int n, const vector<int> &pre,
                                 const vector<int> &cycle,
                                 const set<int> &cycleSet) {
  map<pair<int, int>, int> need;
  map<int, int> pre0CycleCnt;
  for (auto &&x : cycleSet) pre0CycleCnt[x] = 0;
  for (int i = 0; i < n; ++i)
    if (cycle[i] > 0) {
      if (!pre[i])
        ++pre0CycleCnt[cycle[i]];
      else
        for (int j = 1; j < pre[i]; ++j) need[{j, cycle[i]}] = 1;
    }
  for (int i = 0; i < n; ++i)
    if (pre[i] > 0 && cycle[i] > 0) {
      auto it = need.find({pre[i], cycle[i]});
      if (it != need.end()) need.erase(it);
    }
  for (auto &&x : pre0CycleCnt) {
    auto &&y = need[{0, x.first}];
    if (!x.second)
      y = x.first;
    else
      y = ((-x.second % x.first) + x.first) % x.first;
  }
  return need;
}
void f(const int n, vector<int> &pre, vector<int> &cycle,
       const set<int> &cycleSet) {
  auto need = getNeed(n, pre, cycle, cycleSet);
  vector<int> left;
  vector<pair<int, int>> right;
  for (int i = 0; i < n; ++i)
    if (pre[i] < 0 || cycle[i] < 0) left.push_back(i);
  for (auto &&x : need)
    for (int i = x.second; i > 0; --i) right.push_back(x.first);
  vector<vector<int>> adj(left.size());
  for (int i = 0; i < left.size(); ++i)
    for (int j = 0; j < right.size(); ++j) {
      auto &&x = left[i];
      auto &&y = right[j];
      if ((pre[x] < 0 || pre[x] == y.first) &&
          (cycle[x] < 0 || cycle[x] == y.second))
        adj[i].push_back(j + left.size());
    }
  auto res = maxMatching(left.size(), right.size(), adj);
  if (res.first != right.size()) return;
  auto &&match = res.second;
  for (int j = 0; j < right.size(); ++j) {
    auto &&x = left[match[j + left.size()]];
    auto &&y = right[j];
    pre[x] = y.first;
    cycle[x] = y.second;
  }
  int bestPre = 0;
  int cycleWithBestPre = 0;
  for (int i = 0; i < n; ++i)
    if (pre[i] > bestPre) {
      bestPre = pre[i];
      cycleWithBestPre = cycle[i];
    }
  for (int i = 0; i < n; ++i)
    if (pre[i] <= 0 && cycle[i] < 0) {
      pre[i] = 0;
      cycle[i] = 1;
    } else if (cycle[i] < 0)
      cycle[i] = cycleWithBestPre;
    else if (pre[i] < 0)
      pre[i] = 1;
  map<int, vector<int>> pre0Nodes;
  map<pair<int, int>, int> someNode;
  for (int i = 0; i < n; ++i) {
    if (!pre[i]) pre0Nodes[cycle[i]].push_back(i);
    someNode[{pre[i], cycle[i]}] = i;
  }
  vector<int> ans(n);
  for (auto &&x : pre0Nodes) {
    while (!x.second.empty()) {
      vector<int> v(x.second.end() - x.first, x.second.end());
      x.second.erase(x.second.end() - x.first, x.second.end());
      for (int i = 0; i < v.size(); ++i) ans[v[i]] = v[(i + 1) % v.size()];
    }
  }
  for (int i = 0; i < n; ++i)
    if (pre[i] > 0) ans[i] = someNode[{pre[i] - 1, cycle[i]}];
  for (int i = 0; i < n; ++i) {
    if (i) cout << ' ';
    cout << ans[i] + 1;
  }
  exit(0);
}
void f() {
  int n;
  cin >> n;
  vector<int> pre(n), cycle(n);
  int maxPQI = -1;
  for (int i = 0; i < n; ++i) {
    string x, y;
    cin >> x >> y;
    pre[i] = x == "?" ? -1 : stoi(x);
    cycle[i] = y == "?" ? -1 : stoi(y);
    if (pre[i] >= 0 && cycle[i] < 0 && (maxPQI < 0 || pre[i] > pre[maxPQI]))
      maxPQI = i;
  }
  set<int> cycleSet(cycle.begin(), cycle.end());
  cycleSet.erase(-1);
  int sum = 0;
  for (auto &&x : cycleSet) sum += x;
  if (sum > n) return;
  if (maxPQI < 0)
    f(n, pre, cycle, cycleSet);
  else {
    cycle[maxPQI] = 1;
    f(n, pre, cycle, cycleSet);
    for (auto &&x : cycleSet) {
      cycle[maxPQI] = x;
      f(n, pre, cycle, cycleSet);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  f();
  cout << -1;
  return 0;
}