#include <bits/stdc++.h>
using namespace std;
int n, m, id[10], cnt[10], ok[10], E[10][10], ans;
char str1[10], str2[10];
bool check() {
  for (int i = 0, x, y; i < (1 << m) - 1; ++i) {
    x = y = 0;
    for (int j = 0; j < m; ++j)
      if (i >> j & 1) x += cnt[j];
    for (int j = 0; j < m; ++j)
      for (int k = j; k < m; ++k)
        if ((i >> j & 1) | (i >> k & 1)) y += E[j][k];
    if (y < x) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = n; i; i /= 10) ++m;
  for (int i = id[0] = 1; i < m; ++i) id[i] = id[i - 1] * 10;
  for (int i = 0; i < m; ++i) cnt[i] = id[i + 1] - id[i];
  cnt[m - 1] = n - id[m - 1] + 1;
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%s%s", str1, str2);
    x = strlen(str1);
    y = strlen(str2);
    ++E[min(x, y) - 1][max(x, y) - 1];
  }
  if (!check()) return puts("-1"), 0;
  --cnt[0];
  ok[0] = 1;
  id[0] = 2;
  while (ans < n - 1)
    for (int i = 0; i < m; ++i)
      if (ok[i])
        for (int j = 0; j < m; ++j)
          if (cnt[j] && E[min(i, j)][max(i, j)]) {
            --cnt[j];
            --E[min(i, j)][max(i, j)];
            if (check()) {
              printf("%d %d\n", id[i] - 1, id[j]);
              ++id[j];
              ok[j] = 1;
              ++ans;
            } else {
              ++cnt[j];
              ++E[min(i, j)][max(i, j)];
            }
          }
  return 0;
}
