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>
template <typename T>
inline bool chkmax(T &first, T second) {
  return first < second ? first = second, true : false;
}
const int MAXN = 1.1e3 + 5;
std::pair<int, int> a[MAXN];
std::pair<int, int> opt[MAXN];
namespace HGY {
const int MAXNODE = MAXN;
int N, M;
bool vis[MAXNODE];
bool g[MAXNODE][MAXNODE];
int link[MAXNODE];
bool lock[MAXNODE];
bool dfs(int u) {
  int v;
  for (v = 0; v < M; ++v) {
    if (!g[u][v]) continue;
    if (vis[v] || lock[v]) continue;
    vis[v] = true;
    if (!~link[v] || dfs(link[v])) {
      link[v] = u;
      return true;
    }
  }
  return false;
}
bool exec() {
  int i, v;
  if (N > M) return false;
  memset(lock, 0, sizeof(lock));
  memset(link, -1, sizeof(link));
  for (i = 0; i < N; ++i) {
    memset(vis, 0, sizeof(vis));
    for (v = 0; v < M; ++v)
      if (opt[i] == a[v] && !~link[v]) {
        link[v] = i;
        lock[v] = true;
        break;
      }
    if (v == M && !dfs(i)) return false;
  }
  return true;
}
void clear() {
  N = M = 0;
  memset(g, 0, sizeof(g));
  memset(link, -1, sizeof(link));
}
}  // namespace HGY
inline bool ok(std::pair<int, int> fir, std::pair<int, int> sec) {
  return ((fir.first == sec.first || !~fir.first || !~sec.first) &&
          (fir.second == sec.second || !~fir.second || !~sec.second));
}
int getnum() {
  int first;
  static char s[100];
  assert(scanf("%s", s) != EOF);
  if (s[0] == '?') return -1;
  sscanf(s, "%d", &first);
  return first;
}
int n;
int exi[MAXN][MAXN];
int sum[MAXN];
int sym[MAXN][MAXN];
int ans[MAXN];
void link(int u, std::pair<int, int> aim) {
  opt[u] = aim;
  int i;
  for (i = 0; i < n; ++i) HGY::g[u][i] = ok(a[i], aim);
}
void print(int option) {
  static std::vector<int> vec[MAXN];
  int i, j, first, second;
  memset(sym, -1, sizeof(sym));
  memset(ans, -1, sizeof(ans));
  for (i = 0; i < MAXN; ++i) vec[i].clear();
  for (i = 0; i < n; ++i) {
    j = HGY::link[i];
    first = opt[j].first, second = opt[j].second;
    if (!~first) continue;
    sym[first][second] = i;
  }
  for (i = 0; i < n; ++i) {
    j = HGY::link[i];
    first = opt[j].first, second = opt[j].second;
    if (!~first) continue;
    if (first) {
      ans[i] = sym[first - 1][second];
    } else
      vec[second].push_back(i);
  }
  for (i = 1; i <= n; ++i)
    for (j = 0; j < (int)vec[i].size(); ++j)
      ans[vec[i][j]] = vec[i][(j + 1) % i + j / i * i];
  for (i = 0; i < n; ++i)
    if (!~ans[i]) {
      first = a[i].first, second = a[i].second;
      if (~first && ~second) {
        ans[i] = sym[first - 1][second];
      } else if (!~first && ~second) {
        ans[i] = sym[0][second];
      } else if (~first && !~second && first) {
        ans[i] = sym[first - 1][option];
      } else
        ans[i] = i;
    }
  for (i = 0; i < n; ++i) printf("%d%c", ans[i] + 1, " \n"[i + 1 == n]);
  exit(0);
}
void clear() {
  HGY::clear();
  memset(ans, -1, sizeof(ans));
  memset(exi, +0, sizeof(exi));
  memset(sum, 0, sizeof(sum));
}
std::set<std::pair<int, int> > set;
void exec() {
  std::pair<int, int> aim;
  int i, j, k, maxx, BACK;
  clear();
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    a[i].first = getnum();
    a[i].second = getnum();
  }
  for (i = 0; i < n; ++i) {
    if (~a[i].first && ~a[i].second) {
      ++sum[a[i].second];
      ++exi[a[i].second][a[i].first];
    }
  }
  for (i = 0; i < n; ++i) {
    if (!~a[i].first && ~a[i].second) ++sum[a[i].second];
  }
  HGY::M = n;
  for (i = 1; i <= n; ++i) {
    if (!sum[i]) continue;
    if (!exi[i][0]) exi[i][0] = i;
    while (exi[i][0] > 0) {
      for (k = 0; k < i; ++k) link(HGY::N++, std::make_pair(0, i));
      exi[i][0] -= i;
    }
    for (k = n - 1; k > 0 && !exi[i][k]; --k)
      ;
    for (; k > 0; --k) {
      link(HGY::N++, std::make_pair(k, i));
      set.insert(std::make_pair(k, i));
    }
  }
  maxx = -1;
  for (i = 0; i < n; ++i)
    if (!~a[i].second) chkmax(maxx, a[i].first);
  if (~maxx) {
    for (i = 1; i <= n; ++i) {
      BACK = HGY::N;
      for (k = 1; k <= maxx; ++k)
        if (!set.count(std::make_pair(k, i))) {
          link(HGY::N++, std::make_pair(k, i));
        }
      if (!sum[i])
        for (k = 0; k < i; ++k) link(HGY::N++, std::make_pair(0, i));
      if (HGY::exec()) print(i);
      HGY::N = BACK;
    }
  } else if (HGY::exec())
    print(-1);
  puts("-1");
}
int main() {
  if (fopen("D.in", "r") != NULL) {
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
  }
  exec();
  return 0;
}