#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 32;
int ans[N][2], cnt = 0;
int G[10][10], rem[10], hd[10], on[10];
int n, d;
void RD(int &res) {
  res = 0;
  char c;
  while (c = getchar(), c != '?')
    ;
  do {
    ++res;
  } while (c = getchar(), c == '?');
}
bool HALL() {
  for (int S = 0; S < (1 << d); ++S) {
    int tot = 0;
    for (int i = 0; i < d; ++i)
      if (S & (1 << i)) tot += rem[i + 1];
    for (int i = 0; i < d; ++i)
      for (int j = i; j < d; ++j)
        if ((S & (1 << i)) || (S & (1 << j))) tot -= G[i + 1][j + 1];
    if (tot > 0) return 0;
  }
  return 1;
}
void work() {
  for (int e = 1; e <= n - 1; ++e) {
    for (int i = 1; i <= d; ++i)
      for (int j = 1; j <= d; ++j) {
        int &ed = G[min(i, j)][max(i, j)];
        if (hd[i] && rem[j] && ed) {
          --ed;
          --rem[j];
          if (HALL()) {
            if (!hd[j]) hd[j] = on[j];
            ans[++cnt][0] = hd[i];
            ans[cnt][1] = on[j]++;
          } else {
            ++ed;
            ++rem[j];
          }
        }
      }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    static int x, y;
    RD(x);
    RD(y);
    if (x > y) swap(x, y);
    ++G[x][y];
  }
  for (int tmp = n; tmp; tmp /= 10) ++d;
  on[1] = 1;
  for (int i = 2; i <= d; ++i) on[i] = on[i - 1] * 10;
  ++on[1];
  for (int i = 1; i < d; ++i) rem[i] = on[i + 1] - on[i];
  rem[d] = n - on[d] + 1;
  hd[1] = 1;
  if (!HALL()) return printf("-1\n"), 0;
  work();
  if (cnt < n - 1)
    return printf("-1\n"), 0;
  else
    for (int i = 1; i <= cnt; ++i) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
