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
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, rev;
  long long f, cap, x, y;
};
struct Dinic {
  int nodes, src, dst;
  vector<int> dist, q, work;
  vector<vector<edge>> g;
  Dinic(int x) : nodes(x), g(x), dist(x), q(x), work(x) {}
  void add_edge(int s, int t, long long cap, int x = 3, int y = 3) {
    g[s].push_back((edge){t, ((int)g[t].size()), 0, cap, x, y});
    g[t].push_back((edge){s, ((int)g[s].size()) - 1, 0, 0, x, y});
  }
  bool dinic_bfs() {
    fill(dist.begin(), dist.end(), -1);
    dist[src] = 0;
    int qt = 0;
    q[qt++] = src;
    for (int qh = 0; qh < qt; qh++) {
      int u = q[qh];
      for (int i = 0; i < ((int)g[u].size()); i++) {
        edge &e = g[u][i];
        int v = g[u][i].to;
        if (dist[v] < 0 && e.f < e.cap) dist[v] = dist[u] + 1, q[qt++] = v;
      }
    }
    return dist[dst] >= 0;
  }
  long long dinic_dfs(int u, long long f) {
    if (u == dst) return f;
    for (int &i = work[u]; i < ((int)g[u].size()); i++) {
      edge &e = g[u][i];
      if (e.cap <= e.f) continue;
      int v = e.to;
      if (dist[v] == dist[u] + 1) {
        long long df = dinic_dfs(v, min(f, e.cap - e.f));
        if (df > 0) {
          e.f += df;
          g[v][e.rev].f -= df;
          return df;
        }
      }
    }
    return 0;
  }
  long long max_flow(int _src, int _dst) {
    src = _src;
    dst = _dst;
    long long result = 0;
    while (dinic_bfs()) {
      fill(work.begin(), work.end(), 0);
      while (long long delta = dinic_dfs(src, 1e9)) result += delta;
    }
    return result;
  }
};
const int N = 303;
bool cl[N];
bool pl[N][N];
int precycle[N], cycle[N];
int n, furthest = -1;
int need[N][N];
map<pair<int, int>, vector<int>> v;
void doit(int cyc = -1) {
  memset(need, 0, sizeof(need));
  for (int i = 1; i < n + 1; i++) {
    if (cl[i]) {
      for (int j = 0; j < n; j++)
        if (cycle[j] == i && precycle[j] == 0) need[i][0]++;
      if (!need[i][0])
        need[i][0] = i;
      else
        need[i][0] = (i - (need[i][0] % i)) % i;
    }
    bool activated = false;
    for (int j = n + 1; j >= 2; j--) {
      activated = activated || pl[i][j];
      if (activated && !pl[i][j - 1]) need[i][j - 1] = 1;
    }
  }
  map<pair<int, int>, pair<int, int>> usable;
  int id = 0;
  for (int i = 0; i < n; i++)
    if (cycle[i] == -1 || precycle[i] == -1) {
      pair<int, int> p = {cycle[i], precycle[i]};
      if (!usable.count(p))
        usable[p] = {id++, 1};
      else
        usable[p].second++;
    }
  map<pair<int, int>, int> requirements;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++)
      if (need[i][j]) requirements[{i, j}] = need[i][j];
  }
  int nodes = ((int)usable.size()) + ((int)requirements.size());
  Dinic d(nodes + 2);
  for (auto x : usable) d.add_edge(nodes, x.second.first, x.second.second);
  int f = 0;
  for (auto x : requirements) {
    auto p = x.first;
    d.add_edge(id, nodes + 1, x.second);
    f += x.second;
    if (usable.count({-1, -1}))
      d.add_edge(usable[{-1, -1}].first, id, 1e9, p.first, p.second);
    if (usable.count({p.first, -1}))
      d.add_edge(usable[{p.first, -1}].first, id, 1e9, p.first, p.second);
    if (usable.count({-1, p.second}))
      d.add_edge(usable[{-1, p.second}].first, id, 1e9, p.first, p.second);
    id++;
  }
  if (d.max_flow(nodes, nodes + 1) == f) {
    pair<int, int> what[n];
    for (int i = 0; i < n; i++) what[i] = {-1, -1};
    for (auto x : usable) {
      int id = x.second.first;
      for (auto &e : d.g[id])
        if (e.cap && e.f) {
          while (e.f--) {
            pair<int, int> p = {e.x, e.y};
            int which = v[x.first].back();
            what[which] = p;
            v[x.first].pop_back();
          }
        }
    }
    for (int i = 0; i < n; i++)
      if (cycle[i] != -1 && precycle[i] != -1)
        what[i] = {cycle[i], precycle[i]};
    for (int i = 0; i < n; i++)
      if (what[i].first == -1) {
        if (cycle[i] == -1 && precycle[i] == -1)
          what[i] = {1, 0};
        else if (cycle[i] == -1) {
          if (precycle[i])
            what[i] = {cyc, precycle[i]};
          else
            what[i] = {1, 0};
        } else if (precycle[i] == -1)
          what[i] = {cycle[i], 1};
      }
    map<pair<int, int>, vector<int>> g;
    int res[n];
    memset(res, -1, sizeof(res));
    for (int i = 0; i < n; i++) g[what[i]].push_back(i);
    map<pair<int, int>, int> which;
    for (int i = 1; i < n + 1; i++) {
      auto &who = g[{i, 0}];
      for (int j = 0; j < ((int)who.size()); j++) {
        int prev = (j - 1 + i) % i;
        res[who[j]] = who[prev + i * (j / i)];
        which[{i, 0}] = who[j];
      }
    }
    for (int i = 1; i < n + 1; i++)
      for (int j = 1; j < n + 1; j++) {
        auto &who = g[{i, j}];
        for (auto x : who) res[x] = which[{i, j - 1}], which[{i, j}] = x;
      }
    for (int i = 0; i < n; i++) cout << res[i] + 1 << " ";
    cout << '\n';
    exit(0);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s, t;
    cin >> s >> t;
    if (s == "?")
      precycle[i] = -1;
    else
      precycle[i] = stoi(s);
    if (t == "?")
      cycle[i] = -1;
    else
      cycle[i] = stoi(t);
    v[{cycle[i], precycle[i]}].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (cycle[i] != -1) {
      cl[cycle[i]] = 1;
      if (precycle[i] != -1) pl[cycle[i]][precycle[i]] = 1;
    }
    if (cycle[i] == -1 && precycle[i] != -1) {
      if (furthest == -1)
        furthest = i;
      else if (precycle[furthest] < precycle[i])
        furthest = i;
    }
  }
  if (furthest == -1)
    doit();
  else
    for (int i = 1; i < n + 1; i++) {
      cycle[furthest] = i;
      bool before = pl[i][precycle[furthest]];
      bool bef = cl[i];
      pl[i][precycle[furthest]] = 1;
      cl[i] = 1;
      doit(i);
      cl[i] = bef;
      pl[i][precycle[furthest]] = before;
      cycle[furthest] = -1;
    }
  cout << -1 << '\n';
  return 0;
}
