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>
#pragma comment(linker, "/STACK:36777216")
std::uniform_int_distribution<std::mt19937::result_type> udist(0, 1);
std::mt19937 rng;
using namespace std;
FILE *in, *out;
int ri() {
  int a;
  fscanf(in, "%d", &a);
  return a;
}
double rf() {
  double a;
  fscanf(in, "%lf", &a);
  return a;
}
char sbuf[100005];
string rstr() {
  char c;
  char *b = sbuf;
  while (c = fgetc(in)) {
    if (c == '\n' || c == 255) break;
    *b++ = c;
  }
  *b = 0;
  return sbuf;
}
long long nod(long long a, long long b) {
  if (a == 1 || b == 1) return 1;
  if (a == 0) return b;
  if (b == 0) return a;
  return nod(b % a, a);
}
vector<int> primes;
void calculatePrimes() {
  primes.push_back(2);
  for (int i = 3; i < 500000; i += 2) {
    bool bFound = false;
    int m = (int)sqrt((float)i);
    for (int j = 1; j < primes.size() && !bFound && primes[j] <= m; j++)
      bFound = ((i % primes[j]) == 0);
    if (!bFound) primes.push_back(i);
  }
}
void egcd(int a, int b, int &g, int &x, int &y) {
  if (a == 0) {
    g = b;
    x = 0;
    y = 1;
    return;
  }
  egcd(b % a, a, g, y, x);
  x = x - (b / a) * y;
}
int modinv(int a, int m) {
  int g = 0, x = 0, y = 0;
  egcd(a, m, g, x, y);
  return (x + m) % m;
}
bool willBeInTime(vector<int> &f, long long v, long long t) {
  long long mintime = 0;
  for (int i = (0); i < (((f.size()))); ++i) {
    if (mintime > t) return false;
    if (f[i] > v) return false;
    if (2 * f[i] <= v) {
      mintime += f[i];
      continue;
    };
    long long s = v - f[i];
    if (s > f[i]) s = f[i];
    mintime += 2 * (f[i] - s) + s;
  }
  return mintime <= t;
}
bool iterate(map<int, map<int, vector<int>>> &m,
             map<int, map<int, vector<int>>>::iterator st, int ind) {
  ind++;
  while (ind <= st->second.rbegin()->first && st->second[ind].size() > 0) ind++;
  if (ind > st->second.rbegin()->first) {
    st++;
    if (st == m.end()) return true;
    ind = 0;
    int numatzero = st->first - (st->second[0].size() % st->first);
    if (st->second[0].size() != 0 && (st->second[0].size() % st->first) == 0)
      numatzero = 0;
    if (m[-1][ind].size() + st->second[-1].size() + m[-1][-1].size() <
        numatzero)
      return false;
    int n11 = 0;
    if (m[-1][ind].size() + st->second[-1].size() < numatzero) {
      n11 = numatzero - m[-1][0].size() - st->second[-1].size();
      st->second[0].insert(st->second[0].end(), m[-1][-1].end() - n11,
                           m[-1][-1].end());
      m[-1][-1].resize(m[-1][-1].size() - n11);
      numatzero -= n11;
    }
    for (int i = 0; i <= numatzero; i++) {
      if (i > m[-1][ind].size() || numatzero - i > st->second[-1].size())
        continue;
      st->second[0].insert(st->second[0].end(), m[-1][ind].end() - i,
                           m[-1][ind].end());
      m[-1][ind].resize(m[-1][ind].size() - i);
      st->second[0].insert(st->second[0].end(),
                           st->second[-1].end() - numatzero + i,
                           st->second[-1].end());
      st->second[-1].resize(st->second[-1].size() - numatzero + i);
      if (iterate(m, st, ind)) return true;
      st->second[-1].insert(st->second[-1].end(),
                            st->second[0].end() - numatzero + i,
                            st->second[0].end());
      st->second[0].resize(st->second[0].size() - numatzero + i);
      m[-1][ind].insert(m[-1][ind].end(), st->second[0].end() - i,
                        st->second[0].end());
      st->second[0].resize(st->second[0].size() - i);
    }
    if (n11 > 0) {
      m[-1][-1].insert(m[-1][-1].end(), st->second[0].end() - n11,
                       st->second[0].end());
      st->second[0].resize(st->second[0].size() - n11);
    }
    return false;
  }
  if (st->second[-1].size() > 0) {
    st->second[ind].push_back(st->second[-1].back());
    st->second[-1].pop_back();
    if (iterate(m, st, ind)) return true;
    st->second[-1].push_back(st->second[ind].back());
    st->second[ind].pop_back();
  }
  if (m[-1][ind].size() > 0) {
    st->second[ind].push_back(m[-1][ind].back());
    m[-1][ind].pop_back();
    if (iterate(m, st, ind)) return true;
    m[-1][ind].push_back(st->second[ind].back());
    st->second[ind].pop_back();
  }
  if (m[-1][ind].size() == 0 && st->second[-1].size() == 0 &&
      m[-1][-1].size() > 0) {
    st->second[ind].push_back(m[-1][-1].back());
    m[-1][-1].pop_back();
    if (iterate(m, st, ind)) return true;
    m[-1][-1].push_back(st->second[ind].back());
    st->second[ind].pop_back();
  }
  return false;
}
bool canBeSolved(map<int, map<int, vector<int>>> m, int lmo, int n) {
  for (auto &st : m) {
    if (st.first == -1) continue;
    int numatzero = st.first - (st.second[0].size() % st.first);
    if (st.second[0].size() % st.first == 0 && st.second[0].size() != 0)
      numatzero = 0;
    while (m[-1][0].size() < numatzero && st.second[-1].size() > 0) {
      st.second[0].push_back(st.second[-1].back());
      st.second[-1].pop_back();
      numatzero--;
    }
    while (m[-1][0].size() > 0 && st.second[-1].size() < numatzero) {
      st.second[0].push_back(m[-1][0].back());
      m[-1][0].pop_back();
      numatzero--;
    }
    while (m[-1][-1].size() > 0 && m[-1][0].size() < numatzero &&
           st.second[-1].size() < numatzero) {
      st.second[0].push_back(m[-1][-1].back());
      m[-1][-1].pop_back();
      numatzero--;
    }
    if (m[-1][0].size() < numatzero && st.second[-1].size() < numatzero)
      return false;
    for (int i = 1; i < st.second.rbegin()->first; i++) {
      if (st.second[i].size() > 0) continue;
      if (m[-1][i].size() > 0 && st.second[-1].size() > 0) {
        numatzero++;
        continue;
      }
      if (m[-1][i].size() > 0) {
        st.second[i].push_back(m[-1][i].back());
        m[-1][i].pop_back();
        continue;
      }
      if (st.second[-1].size() > 0) {
        st.second[i].push_back(st.second[-1].back());
        st.second[-1].pop_back();
        continue;
      }
      if (m[-1][-1].size() > 0) {
        st.second[i].push_back(m[-1][-1].back());
        m[-1][-1].pop_back();
        continue;
      }
      return false;
    }
    if (numatzero <= st.second[-1].size()) {
      for (int i = 1; i < st.second.rbegin()->first; i++) {
        if (st.second[i].size() > 0) continue;
        if (m[-1][i].size() > 0 && st.second[-1].size() > 0) {
          st.second[i].push_back(st.second[-1].back());
          st.second[-1].pop_back();
          numatzero--;
        }
      }
      while (numatzero) {
        st.second[0].push_back(st.second[-1].back());
        st.second[-1].pop_back();
        numatzero--;
      }
    }
  }
  for (int i = 1; i <= m[lmo].rbegin()->first; i++) {
    int count = 0;
    for (auto &st : m) {
      if (st.first == -1) continue;
      if (st.second.rbegin()->first < i) continue;
      if (st.second[i].size() > 0) continue;
      if (m[-1][i].size() > 0 && st.second[-1].size() > 0) count++;
    }
    if (count <= m[-1][i].size()) {
      for (auto &st : m) {
        if (st.first == -1) continue;
        if (st.second.rbegin()->first < i) continue;
        if (st.second[i].size() > 0) continue;
        if (m[-1][i].size() > 0 && st.second[-1].size() > 0) {
          st.second[i].push_back(m[-1][i].back());
          m[-1][i].pop_back();
        }
      }
    }
  }
  {
    int count = 0;
    for (auto &st : m) {
      if (st.first == -1) continue;
      int numatzero = st.first - (st.second[0].size() % st.first);
      if (st.second[0].size() % st.first == 0 && st.second[0].size() != 0)
        numatzero = 0;
      count += numatzero;
    }
    if (count <= m[-1][0].size()) {
      for (auto &st : m) {
        if (st.first == -1) continue;
        int numatzero = st.first - (st.second[0].size() % st.first);
        if (st.second[0].size() % st.first == 0 && st.second[0].size() != 0)
          numatzero = 0;
        while (numatzero) {
          st.second[0].push_back(m[-1][0].back());
          m[-1][0].pop_back();
          numatzero--;
        }
      }
    }
  }
  if (!iterate(m, m.begin(), 3000)) return false;
  vector<int> par(n);
  while (m[-1][-1].size()) {
    m[1][0].push_back(m[-1][-1].back());
    m[-1][-1].pop_back();
  }
  while (m[-1][0].size()) {
    m[1][0].push_back(m[-1][0].back());
    m[-1][0].pop_back();
  }
  for (auto &i : m[-1]) {
    while (i.second.size()) {
      m[lmo][i.first].push_back(i.second.back());
      i.second.pop_back();
    }
  }
  m.erase(m.find(-1));
  for (auto &st : m) {
    while (st.second[-1].size()) {
      st.second[1].push_back(st.second[-1].back());
      st.second[-1].pop_back();
    }
    for (int i = 0; i < st.second[0].size(); i++) {
      if (i % st.first == 0)
        par[st.second[0][i]] = st.second[0][i + st.first - 1];
      else
        par[st.second[0][i]] = st.second[0][i - 1];
    }
    for (auto &j : st.second) {
      if (j.first < 1) continue;
      for (int i = 0; i < j.second.size(); i++)
        par[j.second[i]] = st.second[j.first - 1][0];
    }
  }
  for (auto i : par) cout << i + 1 << " ";
  return true;
}
int main() {
  rng.seed(time(NULL));
  srand(time(NULL));
  long long n;
  cin >> n;
  vector<pair<int, int>> cl(n);
  vector<int> ch(n);
  map<int, map<int, vector<int>>> m;
  pair<int, int> maxp(-1, -1);
  for (int i = (0); i < (((n))); ++i) {
    int c, p;
    string s;
    cin >> s;
    if (s[0] == '?')
      p = -1;
    else
      p = atoi(s.c_str());
    cin >> s;
    if (s[0] == '?')
      c = -1;
    else
      c = atoi(s.c_str());
    cl[i] = make_pair(p, c);
    ch[i] = -1;
    m[c][p].push_back(i);
    if (maxp < cl[i]) maxp = cl[i];
  }
  if (m.size() == 1 && m.begin()->first == -1) {
    m[1] = m[-1];
    m.erase(m.begin());
    maxp.second = 1;
  }
  for (auto &st : m) {
    if (st.first == -1) continue;
    int numatzero = st.first - (st.second[0].size() % st.first);
    if (st.second[0].size() % st.first == 0 && st.second[0].size() != 0)
      numatzero = 0;
    while (m[-1][0].size() < numatzero && st.second[-1].size() > 0) {
      st.second[0].push_back(st.second[-1].back());
      st.second[-1].pop_back();
      numatzero--;
    }
    while (m[-1][0].size() > 0 && st.second[-1].size() < numatzero) {
      st.second[0].push_back(m[-1][0].back());
      m[-1][0].pop_back();
      numatzero--;
    }
    while (m[-1][-1].size() > 0 && m[-1][0].size() < numatzero &&
           st.second[-1].size() < numatzero) {
      st.second[0].push_back(m[-1][-1].back());
      m[-1][-1].pop_back();
      numatzero--;
    }
    if (m[-1][0].size() < numatzero && st.second[-1].size() < numatzero) {
      cout << -1;
      return 0;
    }
    for (int i = 1; i < st.second.rbegin()->first; i++) {
      if (st.second[i].size() > 0) continue;
      if (m[-1][i].size() > 0 && st.second[-1].size() > 0) continue;
      if (m[-1][i].size() > 0) {
        st.second[i].push_back(m[-1][i].back());
        m[-1][i].pop_back();
        continue;
      }
      if (st.second[-1].size() > 0) {
        st.second[i].push_back(st.second[-1].back());
        st.second[-1].pop_back();
        continue;
      }
      if (m[-1][-1].size() > 0) {
        st.second[i].push_back(m[-1][-1].back());
        m[-1][-1].pop_back();
        continue;
      }
      cout << -1;
      return 0;
    }
  }
  if (maxp.second == -1) {
    int maxe = m[-1][maxp.first].back();
    m[-1][maxp.first].pop_back();
    for (auto &st : m) {
      if (st.first == -1) continue;
      int save = st.second.rbegin()->first;
      st.second[maxp.first].push_back(maxe);
      if (canBeSolved(m, st.first, n)) return 0;
      st.second.erase(++st.second.find(save), st.second.end());
    }
  } else if (canBeSolved(m, maxp.second, n))
    return 0;
  cout << -1;
  return 0;
}