#include <bits/stdc++.h>
using namespace std;
int cnt[10][10];
int hub[10], tot[10], s[10], s1[10];
int b[10];
int n, d, k;
bool check() {
  for (int i = 0; i < (1 << k); i++) {
    int v = 0, e = 0, p = 0;
    for (int j = 0; j < k; j++)
      if (i & (1 << j)) b[p++] = j;
    for (int p1 = 0; p1 < p; p1++) {
      v += tot[b[p1]];
      for (int p2 = 0; p2 < p; p2++) {
        e += cnt[b[p1]][b[p2]];
      }
    }
    if (v && v <= e) return 0;
  }
  return 1;
}
void go(int step) {
  if (step == n - 1) return;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      if (cnt[i][j] == 0) continue;
      cnt[i][j]--;
      if (tot[i]) {
        tot[i]--;
        if (check()) {
          cout << s[i] + s1[i] << ' ' << hub[j] << endl;
          s1[i]++;
          go(step + 1);
          return;
        }
        tot[i]++;
      }
      if (tot[j]) {
        tot[j]--;
        if (check()) {
          cout << s[j] + s1[j] << ' ' << hub[i] << endl;
          s1[j]++;
          go(step + 1);
          return;
        }
        tot[j]++;
      }
      cnt[i][j]++;
    }
  }
}
int len(int x) {
  int res = 0;
  while (x) {
    x /= 10;
    res++;
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    int x = s1.length();
    int y = s2.length();
    x--;
    y--;
    cnt[x][y]++;
  }
  for (int i = 1; i <= n; i++) {
    int t = len(i);
    tot[t - 1]++;
    hub[t - 1] = i;
    k = max(k, t);
  }
  s[0] = 1;
  for (int i = 1; i < 8; i++) s[i] = s[i - 1] * 10;
  if (!check()) {
    cout << -1 << endl;
    return 0;
  }
  go(0);
  return 0;
}
