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>
T abs(T x) {
  return x > 0 ? x : -x;
}
int m;
int n;
int ans;
int nint() {
  int x;
  scanf("%d", &x);
  return x;
}
int c[350];
int pre[350], len[350], maxlen[350], maxpre, was[350];
vector<int> v[350];
int opa[350][350], id2[350];
int get(string s) {
  if (s[0] == '?') return -1;
  stringstream sin(s);
  int x;
  sin >> x;
  return x;
}
int check(int a, int b, int a1, int b1) {
  if (a == -1 || a == a1)
    if (b == -1 || b == b1) return 1;
  return 0;
}
int w[350], p[350];
int matr[350][350];
int go(int x) {
  w[x] = 1;
  for (int i = 0; i < (m); i++)
    if (matr[x][i])
      if (p[i] == -1 || (!w[p[i]] && go(p[i]))) {
        p[i] = x;
        return 1;
      }
  return 0;
}
int check(int id) {
  int oldlen = maxlen[id];
  maxlen[id] = maxpre;
  vector<pair<int, int> > v1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (c[i]); j++) v1.push_back({0, i});
    for (int j = 1; j <= maxlen[i]; j++) v1.push_back({j, i});
  }
  m = ((int)(v1).size());
  if (m > n) {
    maxlen[id] = oldlen;
    return 0;
  }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++)
      matr[i][j] = check(pre[i], len[i], v1[j].first, v1[j].second);
  int match = 0;
  memset(p, -1, sizeof(p));
  for (int i = 0; i < (n); i++) {
    memset(w, 0, sizeof(w));
    if (pre[i] == 0 && len[i] > 1) {
      if (go(i))
        match++;
      else {
        maxlen[id] = oldlen;
        return 0;
      }
    }
  }
  for (int i = 0; i < (n); i++) {
    memset(w, 0, sizeof(w));
    if (!(pre[i] == 0 && len[i] > 1))
      if (go(i)) match++;
  }
  if (match != m) {
    maxlen[id] = oldlen;
    return 0;
  }
  for (int i = 0; i < (m); i++) {
    pre[p[i]] = v1[i].first;
    len[p[i]] = v1[i].second;
  }
  for (int i = 0; i < (n); i++) {
    if (pre[i] == -1 && len[i] == -1) {
      pre[i] = 0;
      len[i] = 1;
    } else if (pre[i] == -1) {
      pre[i] = 1;
    } else if (len[i] == -1) {
      if (pre[i])
        len[i] = id;
      else
        len[i] = 1;
    }
  }
  memset(opa, -1, sizeof(opa));
  for (int i = 0; i < (n); i++) {
    if (opa[pre[i]][len[i]] == -1) opa[pre[i]][len[i]] = i;
    if (!pre[i]) {
      id2[i] = ((int)(v[len[i]]).size());
      v[len[i]].push_back(i);
    }
  }
  for (int i = 0; i < (n); i++) {
    int ans;
    if (pre[i])
      ans = opa[pre[i] - 1][len[i]];
    else {
      int tmp = id2[i] + 1;
      if (tmp % len[i] == 0) tmp -= len[i];
      ans = v[len[i]][tmp];
    }
    cout << ans + 1 << ' ';
  }
  cout << endl;
  return 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) {
    string s1, s2;
    cin >> s1 >> s2;
    pre[i] = get(s1);
    len[i] = get(s2);
  }
  for (int i = 0; i < (n); i++) {
    if (pre[i] == 0 && len[i] != -1) c[len[i]]++;
    if (len[i] != -1) was[len[i]] = 1;
    if (pre[i] != -1) {
      maxpre = max(maxpre, pre[i]);
      if (len[i] != -1) maxlen[len[i]] = max(maxlen[len[i]], pre[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (was[i] && c[i] == 0) c[i] = 1;
    while (c[i] % i) c[i]++;
  }
  int o = *max_element(c, c + n + 1);
  if (o == 0) c[1] = 1;
  for (int id = 1; id <= n; id++)
    if (c[id]) {
      if (check(id)) return 0;
    }
  cout << -1 << endl;
  return 0;
}