#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int M = 2e6 + 7;
const int inf = 1e9;
int n, m, mx, p[N], mn[N], d[M][2], sum = 0;
int a[N][N];
bool check() {
  for (int t = 0, tE = (1 << mx) - 1; t <= tE; t++) {
    int ds = 0, bs = 0;
    for (int i = 1, iE = mx; i <= iE; i++)
      if (t & (1 << (i - 1))) ds += p[i];
    if (!ds) continue;
    for (int i = 1, iE = mx; i <= iE; i++)
      if (t & (1 << (i - 1)))
        for (int j = 1, jE = mx; j <= jE; j++)
          if (t & (1 << (j - 1))) bs += a[i][j];
    if (bs >= ds) return 0;
  }
  return 1;
}
int Cnt(int x) { return x == 0 ? 0 : Cnt(x / 10) + 1; }
char sa[N], sb[N];
bool get() {
  for (int x = 1, xE = mx; x <= xE; x++)
    for (int i = 1, iE = mx; i <= iE; i++)
      if (a[x][i]) {
        if (p[x] > 1) {
          a[x][i]--, p[x]--;
          if (check()) return printf("%d %d\n", mn[x] + p[x], mn[i]), 1;
          a[x][i]++, p[x]++;
        }
        if (p[i] > 1) {
          a[x][i]--, p[i]--;
          if (check()) return printf("%d %d\n", mn[x], mn[i] + p[i]), 1;
          a[x][i]++, p[i]++;
        }
      }
  return 0;
}
int main() {
  scanf("%d", &n), mx = Cnt(n);
  for (int i = 1, iE = n; i <= iE; i++) p[Cnt(i)]++;
  mn[1] = 1;
  for (int i = 2, iE = mx; i <= iE; i++) mn[i] = mn[i - 1] * 10;
  for (int i = 1, iE = n - 1; i <= iE; i++)
    scanf("%s%s", sa, sb), d[i][0] = strlen(sa), d[i][1] = strlen(sb),
                           a[d[i][0]][d[i][1]]++;
  if (!check()) return puts("-1"), 0;
  while (get()) sum++;
  for (int x = 1, xE = mx; x <= xE; x++)
    for (int i = 1, iE = mx; i <= iE; i++)
      if (a[x][i]) printf("%d %d\n", mn[x] + p[x] - 1, mn[i] + p[i] - 1), sum++;
  if (sum != n - 1) assert(0);
  return 0;
}
