#include <bits/stdc++.h>
using namespace std;
int n, m, cnt[10], sta[10], g[10][10], f[10][10], pru[10], deg[10], tag[10];
char s[10];
int cal(int x) {
  int res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
int read() {
  scanf("%s", s);
  int res = 0;
  for (int i = 0; s[i]; i++) res++;
  return res;
}
bool hall() {
  for (int i = 1; i <= m; i++)
    for (int j = i; j <= m; j++) f[i][j] = g[i][j];
  for (int i = 1; i <= m; i++) deg[i] = 1;
  for (int i = 1; i <= m - 2; i++) deg[pru[i]]++;
  for (int i = 1; i <= m - 2; i++) {
    bool ok = 0;
    for (int j = 1; j <= m; j++) {
      if (deg[j] == 1) {
        ok = 1;
        deg[pru[i]]--;
        deg[j]--;
        if (f[min(pru[i], j)][max(pru[i], j)] == 0) return 0;
        f[min(pru[i], j)][max(pru[i], j)]--;
        break;
      }
    }
    if (!ok) return 0;
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    if (deg[i] == 1) {
      x = i;
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (deg[i] == 1) y = i;
  }
  if (f[x][y] == 0) return 0;
  f[x][y]--;
  int tmp;
  for (int i = 1; i < 1 << m; i++) {
    tmp = 0;
    for (int j = 0; j < m; j++)
      if (i & (1 << j)) tmp += cnt[j + 1] - 1;
    for (int j = 0; j < m; j++)
      for (int k = j; k < m; k++)
        if (((1 << j) & i) || (i & (1 << k))) tmp -= f[j + 1][k + 1];
    if (tmp > 0) return 0;
  }
  return 1;
}
bool hall_() {
  int tmp;
  for (int i = 1; i < 1 << m; i++) {
    tmp = 0;
    for (int j = 0; j < m; j++)
      if (i & (1 << j)) tmp += cnt[j + 1];
    for (int j = 0; j < m; j++)
      for (int k = j; k < m; k++)
        if (((1 << j) & i) || (i & (1 << k))) tmp -= g[j + 1][k + 1];
    if (tmp > 0) return 0;
  }
  return 1;
}
void print() {
  for (int i = 1; i <= m; i++) deg[i] = 1;
  for (int i = 1; i <= m - 2; i++) deg[pru[i]]++;
  for (int i = 1; i <= m - 2; i++) {
    for (int j = 1; j <= m; j++) {
      if (deg[j] == 1) {
        deg[pru[i]]--;
        deg[j]--;
        g[min(pru[i], j)][max(pru[i], j)]--;
        printf("%d %d\n", sta[pru[i]], sta[j]);
        break;
      }
    }
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    if (deg[i] == 1) {
      x = i;
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (deg[i] == 1) y = i;
  }
  g[x][y]--;
  printf("%d %d\n", sta[x], sta[y]);
  n -= m;
  for (int i = 1; i <= m; i++) tag[i] = sta[i], sta[i]--, cnt[i]--;
  for (int i = 1; i <= m; i++) {
    while (cnt[i] != 0) {
      for (int j = 1; j <= m; j++) {
        if (g[min(i, j)][max(i, j)]) {
          g[min(i, j)][max(i, j)]--;
          cnt[i]--;
          if (hall_()) {
            printf("%d %d\n", sta[i], tag[j]);
            sta[i]--;
            break;
          }
          cnt[i]++;
          g[min(i, j)][max(i, j)]++;
        }
      }
    }
  }
}
void dfs(int x) {
  if (x == m - 2 + 1) {
    if (hall()) {
      print();
      exit(0);
    }
    return;
  }
  for (int i = 1; i <= m; i++) {
    pru[x] = i;
    dfs(x + 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    if (x > y) swap(x, y);
    g[x][y]++;
  }
  for (int i = 1; i <= n; i++) {
    m = cal(i);
    cnt[m]++;
    sta[m] = i;
  }
  if (m == 1) {
    for (int i = 1; i < n; i++) printf("%d %d\n", i, n);
    return 0;
  }
  dfs(1);
  puts("-1");
}
