#include <bits/stdc++.h>
using namespace std;
int n, N, g[10][10], f[10][10], sz[10], cnt[10], s, t;
int fst[505], nxt[5005], to[5005], w[5005], tt, fac[10], fa[10];
void a2(int x, int y, int z) {
  nxt[++tt] = fst[x];
  fst[x] = tt;
  to[tt] = y;
  w[tt] = z;
  nxt[++tt] = fst[y];
  fst[y] = tt;
  to[tt] = x;
  w[tt] = 0;
}
int q[505], d[505];
bool bfs() {
  int l = 0, r = 0;
  q[0] = s;
  memset(d, 0, sizeof d);
  d[s] = 1;
  while (l <= r)
    for (int x = q[l++], i = fst[x]; i; i = nxt[i])
      if (w[i] && !d[to[i]]) d[q[++r] = to[i]] = d[x] + 1;
  return d[t] > 0;
}
int dfs(int x, int a) {
  if (x == t || a == 0) return a;
  int flow = 0, f;
  for (int i = fst[x]; i; i = nxt[i])
    if (d[to[i]] == d[x] + 1 && (f = dfs(to[i], min(a, w[i]))) > 0) {
      flow += f;
      a -= f;
      w[i] -= f;
      w[i ^ 1] += f;
      if (a == 0) break;
    }
  return flow;
}
bool work() {
  tt = 1;
  memset(fst, 0, sizeof fst);
  int tot = 0, sg = N * (N - 1) / 2;
  for (int i = 1; i <= N; ++i)
    for (int j = i + 1; j <= N; ++j)
      if (g[i][j]) {
        ++tot;
        a2(s, tot, g[i][j]);
        a2(tot, i + sg, g[i][j]);
        f[i][j] = tt - 1;
        a2(tot, j + sg, g[i][j]);
      }
  int ans = 0, flow = 0;
  for (int i = 1; i <= N; ++i) {
    a2(i + sg, t, sz[i]);
    ans += sz[i];
  }
  while (bfs()) flow += dfs(s, 999999999);
  if (flow < ans) return 0;
  for (int i = 1; i <= N; ++i) cnt[i] = g[i][i];
  for (int i = 1; i <= N; ++i)
    for (int j = i + 1; j <= N; ++j)
      if (g[i][j]) {
        int r = w[f[i][j] ^ 1];
        for (int k = 1; k <= r; ++k)
          printf("%d %d\n", fac[j - 1], fac[i - 1] + k + cnt[i]);
        cnt[i] += r;
        r = w[(f[i][j] + 2) ^ 1];
        for (int k = 1; k <= r; ++k)
          printf("%d %d\n", fac[i - 1], fac[j - 1] + k + cnt[j]);
        cnt[j] += r;
      }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= g[i][i]; ++j)
      printf("%d %d\n", fac[i - 1], fac[i - 1] + j);
    if (i > 1) printf("%d %d\n", fac[fa[i] - 1], fac[i - 1]);
  }
  return 1;
}
bool check(int x, int y) {
  if (!g[min(x, y)][max(x, y)]) return 0;
  while (fa[x]) {
    if (fa[x] == y) return 0;
    x = fa[x];
  }
  return 1;
}
void dfs(int k) {
  if (k > N) {
    if (work()) exit(0);
    return;
  }
  for (int i = 1; i <= N; ++i)
    if (i != k && check(i, k)) {
      fa[k] = i;
      if (i < k)
        --g[i][k];
      else
        --g[k][i];
      dfs(k + 1);
      if (i < k)
        ++g[i][k];
      else
        ++g[k][i];
    }
}
int main() {
  scanf("%d", &n);
  char s1[10], s2[10];
  for (int i = 1, t1, t2; i < n; ++i) {
    scanf("%s%s", s1, s2);
    t1 = strlen(s1);
    t2 = strlen(s2);
    if (t1 > t2)
      ++g[t2][t1];
    else
      ++g[t1][t2];
  }
  fac[0] = 1;
  for (int k = n; k; k /= 10, ++N)
    ;
  for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * 10;
  for (int i = 1; i <= N; ++i) {
    if (i == N) {
      sz[i] = n - fac[i - 1];
    } else if (i == 1)
      sz[i] = 8;
    else
      sz[i] = fac[i] - fac[i - 1] - 1;
  }
  for (int i = 1; i <= N; ++i)
    if ((sz[i] -= g[i][i]) < 0) {
      puts("-1");
      return 0;
    }
  s = N + N * (N - 1) / 2 + 1, t = s + 1;
  dfs(2);
  puts("-1");
  return 0;
}
