#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline int Get() {
  static char c;
  static int x;
  x = 0, c = getchar();
  while (c != '?') c = getchar();
  while (c == '?') ++x, c = getchar();
  return x;
}
const int V = 6 * 6 + 6 + 2, E = (6 * 6 * 6 + 6) * 2 + 50;
int To[E], Ne[E], Flow[E], He[V], Now[V], _;
inline void add(int x, int y, int f) {
  ++_;
  To[_] = y, Ne[_] = He[x], Flow[_] = f, He[x] = _;
  ++_;
  To[_] = x, Ne[_] = He[y], Flow[_] = 0, He[y] = _;
}
int S, T, cntv, dis[V];
inline bool Spfa() {
  static int Q[V], ql, qr, i, p, x, y;
  for (i = 1; i <= cntv; ++i) dis[i] = 10000;
  Q[ql = qr = 1] = S, dis[S] = 0;
  while (ql <= qr) {
    x = Q[ql], ++ql;
    for (p = He[x]; p; p = Ne[p])
      if (Flow[p] && dis[y = To[p]] > dis[x] + 1)
        dis[y] = dis[x] + 1, Q[++qr] = y;
  }
  return dis[T] < 10000;
}
inline int Dfs(int x, int flow) {
  if (x == T || !flow) return flow;
  int rest = flow, y, p, f;
  for (p = Now[x]; p; p = Ne[p]) {
    Now[x] = p;
    if (Flow[p] && dis[y = To[p]] == dis[x] + 1) {
      f = Dfs(y, min(rest, Flow[p]));
      Flow[p] -= f, Flow[p ^ 1] += f, rest -= f;
      if (!rest) return flow;
    }
  }
  dis[x] = -1;
  return flow - rest;
}
inline int Dinic() {
  int Ans = 0, i;
  while (Spfa()) {
    for (i = 1; i <= cntv; ++i) Now[i] = He[i];
    Ans += Dfs(S, 200000);
  }
  return Ans;
}
int n, m, G[7][7], c[7], cl[7], cr[7], pw[7];
int d[7][7];
int pr[7];
int id[7][7], idi[7][7], idj[7][7];
int cnt[7][7];
int pos[7];
inline void check() {
  static int deg[7], fa[7], i, j, now, x, y;
  for (i = 1; i <= m; ++i) deg[i] = fa[i] = 0;
  now = 1;
  for (i = 1; i < m; ++i) ++deg[pr[i]];
  for (now = 1; now < m; ++now) {
    for (i = 1; i <= m; ++i)
      if (deg[i] == 0) {
        deg[i] = -1;
        fa[i] = pr[now];
        --deg[fa[i]];
        break;
      }
  }
  for (i = 1; i <= m; ++i)
    for (j = 1; j <= m; ++j) d[i][j] = G[i][j];
  for (i = 1; i < m; ++i) {
    x = i, y = fa[i];
    if (d[x][y])
      --d[x][y];
    else if (d[y][x])
      --d[y][x];
    else
      return;
  }
  cntv = m;
  for (i = 1; i <= m; ++i)
    for (j = 1; j <= m; ++j)
      if (d[i][j]) id[i][j] = ++cntv;
  S = ++cntv, T = ++cntv;
  _ = 1;
  memset(He, 0, (cntv + 1) << 2);
  for (i = 1; i <= m; ++i) add(S, i, c[i] - 1);
  int TOT = 0;
  for (i = 1; i <= m; ++i)
    for (j = 1; j <= m; ++j)
      if (d[i][j]) {
        add(id[i][j], T, d[i][j]);
        add(i, id[i][j], d[i][j]);
        idi[i][j] = _;
        add(j, id[i][j], d[i][j]);
        idj[i][j] = _;
        TOT += d[i][j];
      }
  if (Dinic() < n - m) return;
  for (i = 1; i <= m; ++i) pos[i] = cl[i]++;
  for (i = 1; i < m; ++i)
    x = pos[i], y = pos[fa[i]], cout << x << ' ' << y << '\n';
  for (i = 1; i <= m; ++i)
    for (j = 1; j <= m; ++j)
      if (d[i][j]) {
        cnt[i][j] += Flow[idi[i][j]];
        cnt[j][i] += Flow[idj[i][j]];
      }
  for (i = 1; i <= m; ++i)
    for (j = 1; j <= m; ++j)
      while (cnt[i][j]--) {
        x = pos[j], y = cl[i]++;
        cout << x << ' ' << y << '\n';
      }
  exit(0);
}
inline void dfs(int dep) {
  if (dep > m - 2) {
    pr[dep] = m;
    check();
    return;
  }
  for (int i = 1; i <= m; ++i) {
    pr[dep] = i;
    dfs(dep + 1);
  }
}
int main() {
  int i, x, y;
  read(n);
  for (i = 1; i < n; ++i) {
    x = Get(), y = Get();
    if (x > y) swap(x, y);
    ++G[x][y];
  }
  pw[0] = 1;
  for (i = 1; i <= 6; ++i) pw[i] = pw[i - 1] * 10;
  m = 1;
  while (n >= pw[m]) ++m;
  for (i = 1; i < m; ++i)
    c[i] = pw[i] - pw[i - 1], cl[i] = pw[i - 1], cr[i] = pw[i] - 1;
  c[m] = n - (pw[m - 1] - 1), cl[m] = pw[m - 1], cr[m] = n;
  dfs(1);
  puts("-1");
  return 0;
}
