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;
namespace flow {
const int __ = 1e5 + 7, _ = 1e4 + 7;
struct Edge {
  int end, upEd, f;
} Ed[__];
int cur[_], head[_], dep[_], cntEd, S, T;
queue<int> q;
void addEd(int a, int b, int c) {
  Ed[++cntEd] = (Edge){b, head[a], c};
  head[a] = cntEd;
}
void addE(int a, int b, int c) {
  addEd(a, b, c);
  addEd(b, a, 0);
}
bool bfs() {
  while (!q.empty()) q.pop();
  q.push(S);
  memset(dep, 0, sizeof(int) * (T + 1));
  dep[S] = 1;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i = head[t]; i; i = Ed[i].upEd)
      if (!dep[Ed[i].end] && Ed[i].f) {
        dep[Ed[i].end] = dep[t] + 1;
        q.push(Ed[i].end);
        if (Ed[i].end == T) {
          memcpy(cur, head, sizeof(int) * (T + 1));
          return 1;
        }
      }
  }
  return 0;
}
int dfs(int x, int mn) {
  if (x == T) return mn;
  int sum = 0;
  for (int &i = cur[x]; i; i = Ed[i].upEd)
    if (Ed[i].f && dep[Ed[i].end] == dep[x] + 1) {
      int t = dfs(Ed[i].end, min(Ed[i].f, mn - sum));
      sum += t;
      Ed[i].f -= t;
      Ed[i ^ 1].f += t;
      if (sum == mn) break;
    }
  return sum;
}
int Dinic(int s, int t) {
  S = s;
  T = t;
  int sum = 0;
  while (bfs()) sum += dfs(S, 1e9);
  return sum;
}
void clear() {
  memset(head, 0, sizeof(int) * (T + 1));
  cntEd = 1;
}
}  // namespace flow
using namespace flow;
const int A = 503;
deque<int> p1[A][A], p2[A], p3[A], p4;
int id[A][A], dir[A][A], N, mxd[A], ans[A];
bool vis[A];
pair<int, int> to[A * 4];
int main() {
  scanf("%d", &N);
  vector<int> len;
  for (int i = 1; i <= N; ++i) {
    string D, L;
    cin >> D >> L;
    int p = atoi(D.c_str()), q = atoi(L.c_str());
    if (D == "?" && L == "?")
      p4.push_back(i);
    else if (D == "?") {
      p3[q].push_back(i);
      vis[q] = 1;
    } else if (L == "?") {
      p2[p].push_back(i);
      mxd[0] = max(mxd[0], p);
    } else {
      p1[q][p].push_back(i);
      vis[q] = 1;
      mxd[q] = max(mxd[q], p);
    }
  }
  for (int i = 1; i <= N; ++i)
    if (vis[i]) len.push_back(i);
  if (len.empty()) len.push_back(1);
  int allmx = 0;
  for (int i = 0; i <= N; ++i) allmx = max(allmx, mxd[i]);
  for (auto t : len) {
    int pre = mxd[t], cnt = 0;
    mxd[t] = max(mxd[t], mxd[0]);
    clear();
    for (auto p : len)
      for (int q = 0; q <= mxd[p] && cnt - (int)len.size() <= N; ++q)
        if ((to[id[p][q] = ++cnt] = pair<int, int>(p, q)).second)
          addE(0, cnt, (int)p1[p][q].size());
    if (cnt - (int)len.size() > N) {
      mxd[t] = pre;
      continue;
    }
    addE(0, ++cnt, p4.size());
    for (auto p : len)
      for (int q = 0; q <= mxd[p]; ++q) addE(cnt, id[p][q], 1e9);
    for (auto p : len) {
      addE(0, ++cnt, (int)p3[p].size());
      for (int q = 0; q <= mxd[p]; ++q) addE(cnt, id[p][q], 1e9);
    }
    for (int i = 0; i <= allmx; ++i) addE(0, ++cnt, (int)p2[i].size());
    for (auto p : len)
      for (int q = 0; q <= mxd[p]; ++q) addE(cnt - allmx + q, id[p][q], 1e9);
    ++cnt;
    int num = 0;
    for (auto p : len) {
      for (int q = 1; q <= mxd[p]; ++num, ++q) addE(id[p][q], cnt, 1);
      int val =
          (int)p1[p][0].size()
              ? ((int)p1[p][0].size() % p ? p - (int)p1[p][0].size() % p : 0)
              : p;
      num += val;
      addE(id[p][0], cnt, val);
    }
    if (Dinic(0, cnt) != num) {
      mxd[t] = pre;
      continue;
    }
    cnt = 0;
    for (auto p : len) {
      for (int q = 1; q <= mxd[p]; ++q)
        for (int i = head[id[p][q]]; i; i = Ed[i].upEd)
          if (!Ed[i].end && Ed[i].f) {
            dir[p][q] = p1[p][q].front();
            p1[p][q].pop_front();
          }
      cnt += mxd[p] + 1;
    }
    for (int i = head[++cnt]; i; i = Ed[i].upEd)
      while (Ed[i].end && Ed[i ^ 1].f--) {
        pair<int, int> p = to[Ed[i].end];
        int id = p4.front();
        p4.pop_front();
        p.second ? (void)(dir[p.first][p.second] = id)
                 : p1[p.first][0].push_back(id);
      }
    for (auto q : len)
      for (int i = head[++cnt]; i; i = Ed[i].upEd)
        while (Ed[i].end && Ed[i ^ 1].f--) {
          pair<int, int> p = to[Ed[i].end];
          int id = p3[q].front();
          p3[q].pop_front();
          p.second ? (void)(dir[p.first][p.second] = id)
                   : p1[p.first][0].push_back(id);
        }
    for (int q = 0; q <= allmx; ++q)
      for (int i = head[++cnt]; i; i = Ed[i].upEd)
        while (Ed[i].end && Ed[i ^ 1].f--) {
          pair<int, int> p = to[Ed[i].end];
          int id = p2[q].front();
          p2[q].pop_front();
          p.second ? (void)(dir[p.first][p.second] = id)
                   : p1[p.first][0].push_back(id);
        }
    for (auto p : len) {
      deque<int> &now = p1[p][0];
      dir[p][0] = now.front();
      while ((int)now.size()) {
        for (int i = 0; i + 1 < p; ++i) ans[now[i]] = now[i + 1];
        ans[now[p - 1]] = now[0];
        for (int i = 0; i < p; now.pop_front(), ++i)
          ;
      }
    }
    for (auto p : len)
      for (int q = 1; q <= mxd[p]; ++q) {
        ans[dir[p][q]] = dir[p][q - 1];
        for (auto t : p1[p][q]) ans[t] = dir[p][q - 1];
      }
    for (auto p : len)
      for (auto q : p3[p]) ans[q] = dir[p][0];
    for (int i = 0; i <= allmx; ++i)
      for (auto q : p2[i]) ans[q] = i ? dir[t][i - 1] : q;
    for (auto p : p4) ans[p] = p;
    for (int i = 1; i <= N; ++i) printf("%d ", ans[i]);
    return 0;
  }
  puts("-1");
  return 0;
}