#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
int n, m, a, b, r[20], p[20], c[20][20];
char s1[10], s2[10];
int D(int x) {
  int d = 0;
  while (x) x /= 10, ++d;
  return d;
}
int check() {
  for (int t = (0); t <= ((1 << m) - 1); ++t) {
    a = 0, b = 0;
    for (int i = (1); i <= (m); ++i)
      if (t & (1 << (i - 1))) a += r[i];
    for (int i = (1); i <= (m); ++i)
      if (t & (1 << (i - 1)))
        for (int j = (1); j <= (m); ++j)
          if (t & (1 << (j - 1))) b += c[i][j];
    if (b >= a && a) return 0;
  }
  return 1;
}
int ovo() {
  for (int i = (1); i <= (m); ++i)
    for (int j = (1); j <= (m); ++j)
      if (c[i][j]) {
        if (r[i] > 1) {
          --c[i][j], --r[i];
          if (check()) return printf("%d %d\n", r[i] + p[i], p[j]), 1;
          ++c[i][j], ++r[i];
        }
        if (r[j] > 1) {
          --c[i][j], --r[j];
          if (check()) return printf("%d %d\n", r[j] + p[j], p[i]), 1;
          ++c[i][j], ++r[j];
        }
      }
  return 0;
}
int main() {
  scanf("%d", &n);
  m = D(n);
  for (int i = (1); i <= (n); ++i) ++r[D(i)];
  p[1] = 1;
  for (int i = (2); i <= (m); ++i) p[i] = p[i - 1] * 10;
  for (int i = (1); i <= (n - 1); ++i)
    scanf(" %s %s", s1, s2), ++c[strlen(s1)][strlen(s2)];
  if (!check()) return puts("-1"), 0;
  while (ovo())
    ;
  for (int i = (1); i <= (m); ++i)
    for (int j = (1); j <= (m); ++j)
      if (c[i][j]) printf("%d %d\n", r[i] + p[i] - 1, r[j] + p[j] - 1);
  return 0;
}
