#include <bits/stdc++.h>
const int N_MAX = 200003;
int len, g[7][7], lim[7], now[7], res[7], vis[7];
inline bool Hall() {
  for (int S = 1; S + 1 < 1 << len; ++S) {
    int L = 0, R = 0;
    for (int i = 1; i <= len; ++i)
      if (S >> (i - 1) & 1) L += res[i];
    for (int i = 1; i <= len; ++i)
      for (int j = i; j <= len; ++j)
        if ((S >> (i - 1) & 1) || (S >> (j - 1) & 1)) R += g[i][j];
    if (L > R) return 0;
  }
  return 1;
}
std::pair<int, int> ans[N_MAX];
int main() {
  int n;
  scanf("%d", &n);
  for (int temp = n; temp; temp /= 10) ++len;
  for (int i = 1; i < n; ++i) {
    char s[2][7];
    scanf("%s%s", s[0], s[1]);
    int x = strlen(s[0]), y = strlen(s[1]);
    ++g[x][y], g[y][x] += x != y;
  }
  lim[0] = 1;
  for (int i = 1; i < 7; ++i) lim[i] = lim[i - 1] * 10, now[i] = lim[i - 1];
  for (int i = 1; i < len; ++i) res[i] = lim[i] - lim[i - 1];
  res[len] = n - lim[len - 1] + 1;
  if (!Hall()) {
    printf("-1\n");
    return 0;
  }
  ++now[1], --res[1], vis[1] = 1;
  for (int cnt = 1; cnt < n;) {
    for (int i = 1; i <= len; ++i)
      if (vis[i])
        for (int j = 1; j <= len; ++j)
          if (res[j] && g[i][j]) {
            --res[j], --g[i][j];
            g[j][i] -= i != j;
            if (Hall()) {
              ans[cnt] = std::make_pair(lim[i - 1], now[j]), ++cnt;
              vis[j] = 1, ++now[j];
            } else {
              ++res[j], ++g[i][j];
              g[j][i] += i != j;
            }
          }
  }
  for (int i = 1; i < n; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
