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 int maxn = 1505;
struct node {
  int to, next, flow;
  node(void) {}
  node(int a, int b, int c) : to(a), next(b), flow(c) {}
} e[maxn * maxn];
bool inc[maxn][maxn];
int p_l[maxn], c_l[maxn], mx_p[maxn], co[maxn], final[maxn], s, t, cnt, n,
    max_pre, tot;
int d[maxn], cd[maxn], cur[maxn];
void read(int &x) {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && c != '?')
    ;
  if (c == '?')
    x = -1;
  else
    x = c - 48;
  while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - 48;
}
int dfs(int now, int flow) {
  if (now == t) return flow;
  int use = 0;
  for (int i = cur[now]; i; i = e[i].next) {
    cur[now] = i;
    if (e[i].flow > 0 && d[e[i].to] + 1 == d[now]) {
      int tmp = dfs(e[i].to, min(flow - use, e[i].flow));
      use += tmp, e[i].flow -= tmp, e[i ^ 1].flow += tmp;
      if (use == flow || d[s] == cnt + 1) return use;
    }
  }
  cur[now] = final[now];
  if (!(--cd[d[now]])) d[s] = cnt + 1;
  ++cd[++d[now]];
  return use;
}
void link(int u, int v, int f) {
  e[++tot] = node(v, final[u], f), final[u] = tot;
  e[++tot] = node(u, final[v], 0), final[v] = tot;
}
bool test(int circ) {
  static int ned[maxn], ord[maxn], p_b[maxn], ned_put[305][305];
  memset(ned_put, 0, sizeof ned_put);
  memset(ned, 0, sizeof ned), memcpy(p_b, p_l, sizeof p_l),
      memset(final, 0, sizeof final), memset(cur, 0, sizeof cur);
  s = 0, t = 1, cnt = 1, tot = 1;
  int bak = mx_p[circ];
  mx_p[circ] = max(max_pre, bak);
  for (int i = 1; i <= n; i++) {
    int c = 0;
    for (int j = 1, it = 0; j <= mx_p[i]; j++)
      if (!inc[i][j]) ++c, link(j + 1 + 2 * n, i + 1 + n, 1);
    link(i + 1 + n, t, c);
    c = (i - co[i] % i) % i;
    if (!co[i] && mx_p[i] != -1) c = i;
    link(i + 1, t, c);
  }
  for (int i = 1; i <= n; i++)
    if (c_l[i] == -1 || p_l[i] == -1) {
      int id = i + 3 * n + 1;
      link(s, id, 1);
      for (int j = 1; j <= n; j++)
        if ((p_l[i] == -1 || !p_l[i]) && (c_l[i] == -1 || c_l[i] == j))
          link(id, j + 1, 1);
      for (int j = 1; j <= n; j++)
        if ((p_l[i] == j || p_l[i] == -1) && c_l[i] == -1)
          link(id, j + 1 + 2 * n, 1);
      for (int j = 1; j <= n; j++)
        if (p_l[i] == -1 && (c_l[i] == -1 || c_l[i] == j))
          link(id, j + 1 + n, 1);
    }
  cnt = n * 4 + 1;
  memset(cd, 0, sizeof cd), memset(d, 0, sizeof d);
  cd[0] = cnt + 1;
  for (; d[s] < cnt + 1; dfs(s, 1 << 30))
    ;
  for (int i = final[t]; i; i = e[i].next)
    if (e[i ^ 1].flow) {
      mx_p[circ] = bak;
      memcpy(p_l, p_b, sizeof p_b);
      return 0;
    }
  vector<int> can[maxn];
  memset(can, 0, sizeof can);
  for (int i = 1; i <= n; i++)
    if (c_l[i] == -1 || p_l[i] == -1) {
      bool get = 0;
      for (int j = final[i + 3 * n + 1]; j; j = e[j].next)
        if (e[j].to && !e[j].flow) {
          if (e[j].to > 1 + 2 * n)
            p_l[i] = e[j].to - 1 - 2 * n, c_l[i] = 0, can[p_l[i]].push_back(i);
          else if (e[j].to <= 1 + n)
            p_l[i] = 0, c_l[i] = e[j].to - 1;
          get = 1;
          break;
        }
      if (get) continue;
      if (c_l[i] == -1 && (p_l[i] == -1 || !p_l[i]))
        p_l[i] = 0, c_l[i] = 1;
      else if (c_l[i] == -1)
        c_l[i] = circ;
    }
  for (int i = 1; i <= n; i++)
    for (int j = final[i + 1 + 2 * n]; j; j = e[j].next)
      if (e[j ^ 1].flow && e[j].to <= n * 2 + 1)
        for (int k = e[j ^ 1].flow; k; k--)
          c_l[can[i].back()] = e[j].to - n - 1, can[i].pop_back();
  for (int i = 1; i <= n; i++)
    if (c_l[i] != -1 && p_l[i] != -1)
      inc[c_l[i]][p_l[i]] = 1, mx_p[c_l[i]] = max(mx_p[c_l[i]], p_l[i]);
  for (int i = 1; i <= n; i++) {
    vector<int> ok, els;
    ok.clear(), els.clear();
    for (int j = 1; j <= n; j++)
      if (p_l[j] == -1 && (c_l[j] == i)) ok.push_back(j);
    for (int j = 1; j <= n; j++)
      if (p_l[j] == -1 && c_l[j] == -1) els.push_back(j);
    for (int j = 1; j <= mx_p[i]; j++)
      if (!inc[i][j]) {
        int v;
        if (ok.size())
          v = ok.back(), ok.pop_back();
        else
          v = els.back(), els.pop_back();
        p_l[v] = j, c_l[v] = i;
      }
    for (int j = 1; j <= n; j++)
      if (p_l[j] == -1 && c_l[j] == i) p_l[j] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (p_l[i] == -1 && c_l[i] == -1) c_l[i] = 1, p_l[i] = 0;
  for (int i = 1; i <= n; i++) mx_p[c_l[i]] = max(mx_p[c_l[i]], p_l[i]);
  static int ans[maxn];
  for (int i = 1; i <= n; i++) {
    vector<int> fi;
    fi.clear();
    for (int j = 1; j <= n; j++)
      if (!p_l[j] && c_l[j] == i) fi.push_back(j);
    if (!fi.size()) continue;
    assert(fi.size() % i == 0);
    for (int j = 0; j < fi.size(); j += i)
      for (int k = 0; k < i; k++) ans[fi[j + k]] = fi[j + (k + 1) % i];
    int p = fi[0];
    for (int j = 1; j <= mx_p[i]; j++) {
      int cp = -1;
      for (int k = 1; k <= n; k++)
        if (p_l[k] == j && c_l[k] == i) cp = k, ans[k] = p;
      p = cp;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 1;
}
int main() {
  scanf("%d", &n);
  max_pre = -1;
  memset(mx_p, 255, sizeof mx_p);
  for (int i = 1; i <= n; i++) {
    read(p_l[i]), read(c_l[i]);
    max_pre = max(max_pre, p_l[i]);
    if (c_l[i] != -1) {
      mx_p[c_l[i]] = max(mx_p[c_l[i]], max(0, p_l[i]));
      if (!p_l[i]) co[c_l[i]]++;
      if (p_l[i] > -1) inc[c_l[i]][p_l[i]] = 1;
    }
  }
  for (int c = 1; c <= n; c++)
    if (test(c)) return 0;
  printf("-1\n");
  return 0;
}