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;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << a << " ";
  err(++it, args...);
}
const int M = 310, mod = 1000000007;
int cnt[M][M], ache[M], ans[M];
vector<int> eie[M][M];
vector<pair<int, int> > needed, reserve;
pair<int, int> g[M];
int maxx[M], node[M];
int find_max(int c) {
  for (int i = M - 1; i >= 0; i--)
    if (cnt[c][i]) return i;
  return -1;
}
int visited[M], matched_with[M], left_match[M];
bool find_new_match(int u) {
  for (int v = 0; v < reserve.size(); v++) {
    if (visited[v] == true) continue;
    if (reserve[v] == make_pair(-1, -1) ||
        reserve[v].first == needed[u].first ||
        reserve[v].second == needed[u].second) {
      if (matched_with[v] == -1) {
        matched_with[v] = u;
        left_match[u] = v;
        return true;
      } else if (matched_with[v] != u) {
        visited[v] = true;
        if (find_new_match(matched_with[v])) {
          matched_with[v] = u;
          left_match[u] = v;
          return true;
        }
      }
    }
  }
  return false;
}
int _max_match() {
  int i, _match = 0;
  memset((matched_with), (-1), sizeof(matched_with));
  memset((left_match), (-1), sizeof(left_match));
  _match = 0;
  for (i = 0; i < needed.size(); i++) {
    if (left_match[i] == -1) {
      memset((visited), (false), sizeof(visited));
      if (find_new_match(i)) {
        _match++;
      }
    }
  }
  return _match;
}
int pop_last_elem(vector<int>& p) {
  int k = p[p.size() - 1];
  p.pop_back();
  return k;
}
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k, n, maxlen = 0, gotcha = false;
  char a[100], b[100];
  memset((cnt), (0), sizeof(cnt));
  memset((ache), (0), sizeof(ache));
  memset((ans), (-1), sizeof(ans));
  memset((maxx), (0), sizeof(maxx));
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a >> b;
    g[i].first = a[0] == '?' ? -1 : atoi(a);
    g[i].second = b[0] == '?' ? -1 : atoi(b);
    if (g[i].first != -1 && g[i].second != -1) {
      cnt[g[i].second][g[i].first]++;
      eie[g[i].second][g[i].first].push_back(i);
      maxx[g[i].second] = max(maxx[g[i].second], g[i].first);
    }
    if (g[i].second != -1) ache[g[i].second] = true, gotcha = true;
    if (g[i].second == -1 && g[i].first != -1) maxlen = max(maxlen, g[i].first);
  }
  for (i = 1; i <= n; i++) {
    if (cnt[i][0]) {
      while (cnt[i][0] > i) {
        vector<int> t;
        for (j = 0; j < i; j++) {
          t.push_back(pop_last_elem(eie[i][0]));
          cnt[i][0]--;
        }
        for (j = 0; j < t.size() - 1; j++) ans[t[j]] = t[j + 1];
        ans[t[j]] = t[0];
      }
      cnt[i][0] %= i;
      if (cnt[i][0] == 0) cnt[i][0] = i;
    }
  }
  for (i = 1; i <= n; i++)
    if (g[i].second == -1 || g[i].first == -1)
      node[reserve.size()] = i, reserve.push_back(g[i]);
  if (!gotcha) ache[1] = true;
  int II = -1;
  for (int uu = 1; uu <= n; uu++) {
    if (ache[uu]) {
      needed.clear();
      for (i = 1; i <= n; i++) {
        if (ache[i]) {
          int loop = i == uu ? max(maxlen, maxx[i]) : maxx[i];
          for (j = cnt[i][0] + 1; j <= i; j++)
            needed.push_back(make_pair(0, i));
          for (j = 1; j <= loop; j++)
            if (cnt[i][j] == 0) needed.push_back(make_pair(j, i));
        }
      }
      k = _max_match();
      if (k == needed.size()) {
        II = uu;
        break;
      }
    }
  }
  if (II == -1) {
    printf("%s\n", "-1");
    return 0;
  };
  for (i = 0; i < reserve.size(); i++) {
    if (matched_with[i] == -1) continue;
    pair<int, int> t = needed[matched_with[i]];
    cnt[t.second][t.first]++;
    eie[t.second][t.first].push_back(node[i]);
  }
  int imax = 0, um = 0;
  for (i = 1; i <= n; i++)
    if (find_max(i) > imax) imax = find_max(i), um = i;
  for (i = 0; i < reserve.size(); i++) {
    if (matched_with[i] == -1) {
      pair<int, int> t = reserve[i];
      if (t.first == 0) t.second = 1;
      if (t.second == -1 && t.first == -1) t = make_pair(0, 1);
      if (t.second == -1) t.second = um;
      if (t.first == -1) t.first = 1;
      cnt[t.second][t.first]++;
      eie[t.second][t.first].push_back(node[i]);
    }
  }
  for (i = 1; i <= n; i++) {
    if (cnt[i][0]) {
      if (i == 1) {
        for (j = 0; j < eie[i][0].size(); j++) ans[eie[i][0][j]] = eie[i][0][j];
      } else {
        for (j = 0; j < eie[i][0].size() - 1; j++)
          ans[eie[i][0][j]] = eie[i][0][j + 1];
        ans[eie[i][0][j]] = eie[i][0][0];
      }
      for (j = 1; j <= find_max(i); j++) {
        for (k = 0; k < eie[i][j].size(); k++) {
          ans[eie[i][j][k]] = eie[i][j - 1][0];
        }
      }
    }
  }
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}