#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
int con[10][10], sz[10];
queue<int> a[10];
vector<pair<int, int> > ans;
int cnt_dgt(int n) {
  int res = 0;
  while (n) res++, n /= 10;
  return res;
}
int cnt_v[1 << 10], cnt_e[1 << 10];
bool can(int u, int v) {
  for (int i = 0; i < (1 << 6); i++)
    if (((1 << (u - 1)) & i) && !((1 << (v - 1)) & i)) {
      if (cnt_e[i] && cnt_v[i] - 2 < cnt_e[i]) return false;
    }
  for (int i = 0; i < (1 << 6); i++)
    if (((1 << (u - 1)) & i)) {
      cnt_v[i]--;
      if ((1 << (v - 1)) & i) cnt_e[i]--;
    }
  return true;
}
bool solve() {
  while (true) {
    int flg = false, tot = 0;
    for (int i = 1; i <= 6; i++)
      if (!a[i].empty()) {
        if (a[i].size() == 1 && sz[i] > 1) continue;
        int leaf = a[i].front();
        a[i].pop();
        for (int j = 1; j <= 6; j++) {
          if (!a[j].empty() && con[i][j]) {
            con[i][j]--, sz[i]--;
            if (i != j) con[j][i]--, sz[j]--;
            if (can(i, j)) {
              ans.push_back(make_pair(leaf, a[j].front()));
              flg = true;
              break;
            }
            con[i][j]++, sz[i]++;
            if (i != j) con[j][i]++, sz[j]++;
          }
        }
        if (flg) break;
        a[i].push(leaf);
      }
    for (int i = 1; i <= 6; i++)
      for (int j = 1; j <= 6; j++) tot += con[i][j];
    if (!tot) break;
    if (!flg) return false;
  }
  return true;
}
void preprocess() {
  for (int i = 0; i < (1 << 6); i++) {
    for (int j = 0; j < 6; j++)
      if ((1 << j) & i) cnt_v[i] += a[j + 1].size();
    for (int j = 1; j <= 6; j++) {
      for (int k = j; k <= 6; k++) {
        if (((1 << (j - 1)) & i) && ((1 << (k - 1)) & i)) cnt_e[i] += con[j][k];
      }
    }
  }
  for (int i = 1; i <= 6; i++)
    for (int j = 1; j <= 6; j++) sz[i] += con[i][j];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    char buf[2][10];
    scanf("%s%s", buf, buf + 1);
    int u = strlen(buf[0]);
    int v = strlen(buf[1]);
    con[u][v]++;
    if (u != v) con[v][u]++;
  }
  for (int i = 1; i <= n; i++) {
    a[cnt_dgt(i)].push(i);
  }
  preprocess();
  if (solve())
    for (auto it : ans) printf("%d %d\n", it.first, it.second);
  else
    puts("-1");
  return 0;
}
