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;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template <class T>
bool setmax(T& _a, T _b) {
  if (_b > _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
bool setmin(T& _a, T _b) {
  if (_b < _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T _a, T _b) {
  return _b == 0 ? _a : gcd(_b, _a % _b);
}
struct Entry {
  int dep, cir;
  int i;
};
vector<Entry> read_entries() {
  const auto parse = [](string s) {
    if (s == "?") return -1;
    return stoi(s);
  };
  int n;
  cin >> n;
  vector<Entry> entries(n);
  for (int i = int(0); i <= int((n)-1); ++i) {
    string d, c;
    cin >> d >> c;
    entries[i].dep = parse(d);
    entries[i].cir = parse(c);
    entries[i].i = i;
  }
  return entries;
}
struct BipartiteGraph {
  const int n, m;
  vector<vector<bool>> g;
  BipartiteGraph(int _n, int _m) : n(_n), m(_m), g(n, vector<bool>(m, false)) {}
  void add_edge(int i, int j) { g[i][j] = true; }
  vector<int> match() {
    vector<int> lnk(m, -1), ans(n, -1);
    for (int cur = int(0); cur <= int((n)-1); ++cur) {
      vector<bool> vis(m, false);
      const function<bool(int)> find = [&](int i) {
        for (int j = int(0); j <= int((m)-1); ++j)
          if (g[i][j] && !vis[j]) {
            vis[j] = true;
            if (lnk[j] < 0 || find(lnk[j])) {
              lnk[j] = i, ans[i] = j;
              return true;
            }
          }
        return false;
      };
      if (!find(cur)) return vector<int>();
    }
    return ans;
  }
};
struct FGraph {
  vector<Entry> circle;
  vector<Entry> leaves;
};
vector<int> answers;
void build_functional_graph(FGraph g) {
  int cir = g.circle[0].cir;
  assert(static_cast<int>((g.circle).size()) == cir);
  map<int, vector<int>> m;
  for (const auto& e : g.circle) m[0].push_back(e.i);
  for (const auto& e : g.leaves) m[e.dep].push_back(e.i);
  for (int i = int(0); i <= int((cir)-1); ++i)
    answers[m[0][i]] = m[0][(i + 1) % cir];
  for (const auto& kv : m)
    if (kv.first > 0) {
      for (int i : kv.second) answers[i] = m[kv.first - 1][0];
    }
}
bool solve(int force_cir, int force_depth, map<int, vector<FGraph>> m,
           vector<Entry> entries) {
  struct Requirement {
    int dep, cir, c_index;
  };
  vector<Requirement> reqs;
  for (const auto& kv : m) {
    const int cir = kv.first;
    for (int i = int(0); i <= int((static_cast<int>((kv.second).size())) - 1);
         ++i) {
      const FGraph& g = kv.second[i];
      for (int _ = int(0);
           _ <= int((cir - static_cast<int>((g.circle).size())) - 1); ++_) {
        reqs.push_back({0, cir, i});
      }
      set<int> depths;
      if (cir == force_cir && i == 0) {
        depths.insert(force_depth);
      } else {
        depths.insert(0);
      }
      for (const auto& e : g.leaves) {
        depths.insert(e.dep);
      }
      int max_depth = *depths.rbegin();
      for (int d = int(1); d <= int(max_depth); ++d) {
        if (depths.count(d) == 0) {
          reqs.push_back({d, cir, i});
        }
      }
    }
  }
  vector<bool> used(static_cast<int>((entries).size()), false);
  if (static_cast<int>((reqs).size()) > 0) {
    BipartiteGraph g(static_cast<int>((reqs).size()),
                     static_cast<int>((entries).size()));
    for (int i = int(0); i <= int((static_cast<int>((reqs).size())) - 1); ++i)
      for (int j = int(0); j <= int((static_cast<int>((entries).size())) - 1);
           ++j) {
        if (entries[j].cir >= 0 && entries[j].cir != reqs[i].cir) continue;
        if (entries[j].dep >= 0 && entries[j].dep != reqs[i].dep) continue;
        g.add_edge(i, j);
      }
    vector<int> match = g.match();
    if (match.empty()) return false;
    for (int i = int(0); i <= int((static_cast<int>((reqs).size())) - 1); ++i) {
      int j = match[i];
      used[j] = true;
      entries[j].cir = reqs[i].cir;
      entries[j].dep = reqs[i].dep;
      if (reqs[i].dep == 0) {
        m[reqs[i].cir][reqs[i].c_index].circle.push_back(entries[j]);
      } else {
        m[reqs[i].cir][reqs[i].c_index].leaves.push_back(entries[j]);
      }
    }
  }
  for (int i = int(0); i <= int((static_cast<int>((entries).size())) - 1); ++i)
    if (!used[i]) {
      auto& e = entries[i];
      if (e.cir >= 0) {
        e.dep = 1;
        m[e.cir][0].leaves.push_back(e);
      } else if (e.dep != 0) {
        if (e.dep < 0) e.dep = 1;
        e.cir = force_cir;
        m[force_cir][0].leaves.push_back(e);
      } else {
        e.cir = 1;
        m[1].push_back(FGraph());
        m[1].back().circle.push_back(e);
      }
    }
  for (const auto& kv : m) {
    for (const auto& fg : kv.second) {
      build_functional_graph(fg);
    }
  }
  for (int i : answers) cout << i + 1 << " ";
  cout << endl;
  return true;
}
int main() {
  auto entries = read_entries();
  answers.resize(static_cast<int>((entries).size()));
  map<int, vector<FGraph>> m;
  auto tmp = entries;
  entries.clear();
  for (const auto& e : tmp) {
    if (e.dep >= 0 && e.cir >= 0) {
      if (m.count(e.cir) == 0) {
        m[e.cir].push_back(FGraph());
      }
      if (e.dep == 0) {
        if (static_cast<int>((m[e.cir].back().circle).size()) == e.cir) {
          m[e.cir].push_back(FGraph());
        }
        m[e.cir].back().circle.push_back(e);
      } else {
        m[e.cir][0].leaves.push_back(e);
      }
    } else {
      entries.push_back(e);
    }
  }
  for (const auto& e : entries) {
    if (e.cir >= 0 && m.count(e.cir) == 0) {
      m[e.cir].push_back(FGraph());
    }
  }
  if (m.empty()) {
    m[1].push_back(FGraph());
  }
  int max_depth = 0;
  for (const auto& e : entries) {
    setmax(max_depth, e.dep);
  }
  bool ok = false;
  for (auto& kv : m) {
    if (solve(kv.first, max_depth, m, entries)) {
      ok = true;
      break;
    }
  }
  if (!ok) cout << -1 << endl;
  return 0;
}