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 <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <typename T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <typename T>
inline void println(T first) {
  print(first), putchar('\n');
}
template <typename T>
inline void printsp(T first) {
  print(first), putchar(' ');
}
template <class T, class T1>
inline void print(T first, T1 second) {
  printsp(first), println(second);
}
template <class T, class T1, class T2>
inline void print(T first, T1 second, T2 z) {
  printsp(first), printsp(second), println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
pair<int, int> p[333];
vector<int> V[333];
vector<int> C[333][333];
vector<int> L[333];
vector<int> G;
int n, sz[333];
int To[333];
int VV, E, src, tar;
int head[1111], work[1111], dis[1111];
int to[33333], cap[33333], nxt[33333];
int q[1111], qf, qb;
void init(int n, int s, int t) {
  VV = n;
  E = 0;
  src = s;
  tar = t;
  memset(head, -1, sizeof(int) * VV);
}
void add_edge(int u, int v, int c) {
  to[E] = v;
  cap[E] = c;
  nxt[E] = head[u];
  head[u] = E++;
  to[E] = u;
  cap[E] = 0;
  nxt[E] = head[v];
  head[v] = E++;
}
bool bfs() {
  memset(dis, -1, sizeof(int) * VV);
  qf = qb = 0;
  q[qb++] = src;
  dis[src] = 0;
  while (qf < qb && dis[tar] == -1) {
    int u = q[qf++];
    for (int i = head[u]; i >= 0; i = nxt[i]) {
      int v = to[i];
      if (dis[v] == -1 && cap[i] > 0) {
        dis[v] = dis[u] + 1;
        q[qb++] = v;
      }
    }
  }
  return dis[tar] >= 0;
}
int dfs(int u, int &bot) {
  int v, bot1, delta;
  if (u == tar) return bot;
  for (int &i = work[u]; i >= 0; i = nxt[i]) {
    int v = to[i];
    if (dis[v] != dis[u] + 1 || cap[i] == 0) continue;
    bot1 = min(bot, cap[i]);
    if (delta = dfs(v, bot1)) {
      cap[i] -= delta;
      cap[i ^ 1] += delta;
      bot = bot1;
      return delta;
    }
  }
  return 0;
}
int dinic() {
  int ans = 0, delta, bot;
  while (bfs()) {
    memcpy(work, head, sizeof(int) * VV);
    delta = 0x3f3f3f3f;
    while (delta = dfs(src, bot = 0x3f3f3f3f)) ans += delta;
  }
  return ans;
}
pair<int, int> pos[1111];
void solve(int id) {
  int nn = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= sz[i]; j++) {
      if (C[i][j].empty() || j == 0 && C[i][j].size() % i) nn++;
    }
  }
  if (nn > n) return;
  init(nn + n + n + 10, 0, nn + n + n + 2);
  int cur = 0, flow = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= sz[i]; j++) {
      if (C[i][j].empty() || j == 0 && C[i][j].size() % i) {
        int cap;
        if (j)
          cap = 1;
        else
          cap =
              (max(1, (int)(C[i][j].size() + i - 1) / i)) * i - C[i][j].size();
        flow += cap;
        add_edge(src, ++cur, cap);
        pos[cur] = pair<int, int>(i, j);
        add_edge(cur, nn + i, cap);
        add_edge(cur, nn + n + j + 1, cap);
        add_edge(cur, nn + n + n + 1, cap);
      }
    }
    add_edge(nn + i, tar, V[i].size());
  }
  for (int i = 0; i < n; i++) add_edge(nn + n + i + 1, tar, L[i].size());
  add_edge(nn + n + n + 1, tar, G.size());
  if (dinic() < flow) return;
  for (int i = 1; i <= n; i++) {
    for (int e = head[nn + i]; ~e; e = nxt[e]) {
      int j = to[e];
      if (j == tar) continue;
      int second = pos[j].second, f = cap[e];
      while (f--) {
        C[i][second].push_back(V[i].back());
        V[i].pop_back();
      }
    }
    while (!V[i].empty()) {
      C[i][1].push_back(V[i].back());
      V[i].pop_back();
    }
  }
  for (int i = 0; i < n; i++) {
    for (int e = head[nn + n + i + 1]; ~e; e = nxt[e]) {
      int j = to[e];
      if (j == tar) continue;
      int first = pos[j].first, f = cap[e];
      while (f--) {
        C[first][i].push_back(L[i].back());
        L[i].pop_back();
      }
    }
    while (!L[i].empty()) {
      C[i == 0 ? 1 : id][i].push_back(L[i].back());
      L[i].pop_back();
    }
  }
  for (int e = head[nn + n + n + 1]; ~e; e = nxt[e]) {
    int j = to[e];
    if (j == tar) continue;
    int first = pos[j].first, second = pos[j].second, f = cap[e];
    while (f--) {
      C[first][second].push_back(G.back());
      G.pop_back();
    }
  }
  while (!G.empty()) {
    C[1][0].push_back(G.back());
    G.pop_back();
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      if (C[i][j].empty()) break;
      if (j == 0) {
        for (int k = 0; k < C[i][j].size(); k++) {
          if (k % i == i - 1)
            To[C[i][j][k]] = C[i][j][k - i + 1];
          else
            To[C[i][j][k]] = C[i][j][k + 1];
        }
      } else {
        for (int k = 0; k < C[i][j].size(); k++)
          To[C[i][j][k]] = C[i][j - 1][0];
      }
    }
  }
  for (int i = 1; i <= n; i++) assert(To[i] > 0), printsp(To[i]);
  puts("");
  exit(0);
}
int main() {
  gn(n);
  char A[11], B[11];
  for (int i = 1; i <= n; i++) {
    scanf("%s %s", A, B);
    if (A[0] == '?') {
      p[i].first = -1;
      if (B[0] == '?')
        G.push_back(i), p[i].second = -1;
      else
        V[p[i].second = atoi(B)].push_back(i);
    } else {
      p[i].first = atoi(A);
      if (B[0] == '?')
        L[p[i].first].push_back(i), p[i].second = -1;
      else
        C[p[i].second = atoi(B)][p[i].first].push_back(i);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    sz[i] = -V[i].empty();
    for (int j = 0; j <= n; j++)
      if (C[i][j].size()) sz[i] = j;
    cnt += sz[i] >= 0;
  }
  if (cnt == 0) sz[1] = 0;
  int mxsz = 0;
  for (int i = 1; i <= n; i++)
    if (L[i].size()) mxsz = i;
  if (mxsz) {
    for (int i = 1; i <= n; i++)
      if (sz[i] >= 0) {
        int tmp = sz[i];
        C[i][mxsz].push_back(L[mxsz].back());
        smax(sz[i], mxsz);
        L[mxsz].pop_back();
        solve(i);
        sz[i] = tmp;
        L[mxsz].push_back(C[i][mxsz].back());
        C[i][mxsz].pop_back();
      }
  } else
    solve(1);
  puts("-1");
  return 0;
}