#include <bits/stdc++.h>
using namespace std;
const double dInf = 1E90;
const long long lInf = (long long)1E16;
const int Inf = 0x23333333;
const int N = 200005, M = 7;
vector<int> all[M];
vector<pair<int, int> > f[M][M];
int w[M][M], sz[M];
int n, m;
pair<int, int> e[N];
bool chk() {
  for (int i = 0, LIM = m; i < LIM; ++i)
    if (!sz[i])
      for (int j = 0, LIM = m; j < LIM; ++j)
        if (w[i][j]) return 1;
  for (int S = 1, LIM = (1 << m); S < LIM; ++S) {
    int node = 0, edge = 0;
    for (int temp = S; temp; temp -= (temp & -temp)) {
      int i = __builtin_ctz(temp & -temp);
      node += sz[i];
      for (int T1 = S; T1; T1 -= (T1 & -T1)) {
        int j = __builtin_ctz(T1 & -T1);
        if (j > i) break;
        edge += w[i][j];
      }
    }
    if (node && node <= edge) return 1;
  }
  return 0;
}
void preprocessing() {
  scanf("%d", &n);
  for (int i = 0, LIM = n; i < LIM; ++i) {
    int x = i + 1, temp = x, ws = -1;
    do {
      ++ws, temp /= 10;
    } while (temp);
    all[ws].push_back(x), m = max(m, ws + 1);
  }
  for (int i = 0, LIM = m; i < LIM; ++i) sz[i] = all[i].size();
  char s[10], s1[10];
  for (int i = 1, LIM = n; i < LIM; ++i) {
    scanf("%s", s), scanf("%s", s1);
    int x = strlen(s) - 1, y = strlen(s1) - 1;
    ++w[x][y], e[i] = make_pair(x, y);
    if (x != y) ++w[y][x];
  }
}
void solve() {
  if (chk()) {
    printf("-1");
    return;
  }
  for (int Case = 1, LIM = n; Case < LIM; ++Case) {
    bool done = 0;
    for (int i = 0, LIM = m; i < LIM; ++i) {
      for (int j = 0, LIM = m; j < LIM; ++j)
        if (w[i][j]) {
          --w[i][j], --sz[i];
          if (i != j) --w[j][i];
          if (!chk()) {
            f[min(i, j)][max(i, j)].push_back(
                make_pair(all[i].back(), all[j][0]));
            all[i].pop_back(), done = 1;
            break;
          }
          ++w[i][j], ++sz[i];
          if (i != j) ++w[j][i];
        }
      if (done) break;
    }
    if (!done) break;
  }
  for (int i = 1, LIM = n; i < LIM; ++i) {
    pair<int, int> temp;
    if (e[i].first > e[i].second)
      temp = f[e[i].second][e[i].first].back();
    else
      temp = f[e[i].first][e[i].second].back();
    if (temp.first > temp.second) swap(temp.first, temp.second);
    if (e[i].first > e[i].second)
      printf("%d %d\n", temp.second, temp.first);
    else
      printf("%d %d\n", temp.first, temp.second);
    if (e[i].first > e[i].second)
      f[e[i].second][e[i].first].pop_back();
    else
      f[e[i].first][e[i].second].pop_back();
  }
}
int main() {
  preprocessing();
  solve();
  return 0;
}
