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 long long mod = 1000000007;
const int MAXN = 1000;
const int INF = 1000000000;
struct edge {
  int a, b;
  long long cap, flow;
};
int N, s, t, d[MAXN], ptr[MAXN], q[MAXN];
vector<edge> e;
vector<int> g[MAXN];
void clear_all() {
  for (int i = 0; i < MAXN; i++) {
    d[i] = 0;
    ptr[i] = 0;
    q[i] = 0;
    g[i].clear();
  }
  e.clear();
}
void add_edge(int a, int b, long long cap) {
  edge e1 = {a, b, cap, 0};
  edge e2 = {b, a, 0, 0};
  g[a].push_back((int)e.size());
  e.push_back(e1);
  g[b].push_back((int)e.size());
  e.push_back(e2);
}
bool bfs() {
  int qh = 0, qt = 0;
  q[qt++] = s;
  memset(d, -1, N * sizeof d[0]);
  d[s] = 0;
  while (qh < qt && d[t] == -1) {
    int v = q[qh++];
    for (size_t i = 0; i < g[v].size(); ++i) {
      int id = g[v][i], to = e[id].b;
      if (d[to] == -1 && e[id].flow < e[id].cap) {
        q[qt++] = to;
        d[to] = d[v] + 1;
      }
    }
  }
  return d[t] != -1;
}
long long dfs(int v, long long flow) {
  if (!flow) return 0;
  if (v == t) return flow;
  for (; ptr[v] < (int)g[v].size(); ++ptr[v]) {
    int id = g[v][ptr[v]], to = e[id].b;
    if (d[to] != d[v] + 1) continue;
    long long pushed = dfs(to, min(flow, e[id].cap - e[id].flow));
    if (pushed) {
      e[id].flow += pushed;
      e[id ^ 1].flow -= pushed;
      return pushed;
    }
  }
  return 0;
}
long long dinic() {
  long long flow = 0;
  for (;;) {
    if (!bfs()) break;
    memset(ptr, 0, N * sizeof ptr[0]);
    while (1) {
      long long pushed = dfs(s, INF);
      flow += pushed;
      if (pushed == 0) break;
    }
  }
  return flow;
}
char ps[10], pw[10];
int main() {
  int n;
  scanf("%d\n", &n);
  std::vector<int> p(n), w(n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s\n", ps, pw);
    string sp = ps;
    string sw = pw;
    if (sp == "?")
      p[i] = -1;
    else
      p[i] = stoi(sp);
    if (sw == "?")
      w[i] = -1;
    else
      w[i] = stoi(sw);
  }
  map<std::pair<int, int>, int> to;
  set<int> c;
  int maxu = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] >= 0 && w[i] >= 0) to[make_pair(p[i], w[i])]++;
    if (w[i] >= 0) c.insert(w[i]);
    if (w[i] == -1) {
      maxu = max(maxu, p[i]);
    }
  }
  if (c.empty()) {
    c.insert(1);
  }
  int totcnt = 0;
  for (auto U : to) totcnt += U.second;
  if (totcnt > n) {
    cout << -1;
    return 0;
  }
  for (auto l : c) {
    if (to[make_pair(0, l)] == 0) to[make_pair(0, l)]++;
    while (to[make_pair(0, l)] % l != 0) to[make_pair(0, l)]++;
  }
  for (int lad = 1; lad < 301; lad++) {
    if (to[make_pair(0, lad)] == 0) continue;
    int camp = 0;
    for (int i = 1; i < 301; i++)
      if (to[make_pair(i, lad)] > 0) camp = i;
    for (int i = camp + 1; i < maxu + 1; i++) to[make_pair(i, lad)]++;
    set<std::pair<int, int> > add;
    for (auto x : to) {
      if (x.second == 0) continue;
      int l = x.first.second;
      int d = x.first.first;
      for (int i = 1; i < d; i++)
        if (to[make_pair(i, l)] == 0) add.insert(make_pair(i, l));
    }
    for (auto x : add) to[x]++;
    std::vector<std::pair<int, int> > r;
    std::vector<std::pair<int, int> > tp(n, make_pair(-1, -1));
    for (int i = 0; i < n; i++) {
      if (p[i] >= 0 && w[i] >= 0) {
        to[make_pair(p[i], w[i])]--;
        tp[i] = make_pair(p[i], w[i]);
      }
    }
    for (auto x : to) {
      for (int i = 0; i < x.second; i++) r.push_back(x.first);
    }
    for (int i = 0; i < n; i++) {
      if (p[i] >= 0 && w[i] >= 0) {
        to[make_pair(p[i], w[i])]++;
      }
    }
    for (int i = camp + 1; i < maxu + 1; i++) to[make_pair(i, lad)]--;
    if (r.size() > n) {
      continue;
    }
    int rn = r.size();
    clear_all();
    N = 2 + rn + n;
    s = N - 2;
    t = N - 1;
    for (int i = 0; i < rn; i++) add_edge(s, i, 1);
    for (int i = 0; i < n; i++)
      if (tp[i] == make_pair(-1, -1)) add_edge(rn + i, t, 1);
    for (int i = 0; i < rn; i++) {
      for (int j = 0; j < n; j++) {
        if (tp[j] != make_pair(-1, -1)) continue;
        if (p[j] >= 0 && p[j] != r[i].first) continue;
        if (w[j] >= 0 && w[j] != r[i].second) continue;
        add_edge(i, rn + j, 1);
      }
    }
    if (dinic() < rn) {
      continue;
    }
    for (auto ed : e) {
      if (ed.a < rn && ed.b >= rn && ed.b < rn + n && ed.flow == 1) {
        tp[ed.b - rn] = r[ed.a];
      }
    }
    int cnt0 = 0;
    for (int i = 0; i < n; i++) {
      if (tp[i] == make_pair(-1, -1) && p[i] == 0) cnt0++;
    }
    for (int i = 0; i < n; i++) {
      if (tp[i] == make_pair(-1, -1) && p[i] == 0) tp[i] = make_pair(0, cnt0);
    }
    for (int i = 0; i < n; i++) {
      if (tp[i] == make_pair(-1, -1)) {
        if (p[i] == -1 && w[i] == -1)
          tp[i] = make_pair(0, 1);
        else if (p[i] == -1)
          tp[i] = make_pair(1, w[i]);
        else if (w[i] == -1)
          tp[i] = make_pair(p[i], lad);
      }
    }
    std::vector<int> ans(n);
    for (int l = 1; l < 301; l++) {
      std::vector<int> ind;
      for (int i = 0; i < n; i++)
        if (tp[i] == make_pair(0, l)) ind.push_back(i);
      for (int i = 0; i < ind.size() / l; i++) {
        for (int j = 0; j < l; j++) {
          ans[ind[i * l + j]] = ind[i * l + (j + 1) % l] + 1;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (tp[i].first != 0) {
        std::pair<int, int> nd = tp[i];
        nd.first--;
        for (int j = 0; j < n; j++)
          if (tp[j] == nd) ans[i] = j + 1;
      }
    }
    for (int i = 0; i < n; i++) cout << ans[i] << ' ';
    return 0;
  }
  cout << -1;
  return 0;
}