#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? EOF : *ib++;
}
inline int read() {
  char ch = gc();
  int res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline long long readll() {
  char ch = gc();
  long long res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline int readstring(char *s) {
  int top = 0;
  char ch = gc();
  while (isspace(ch)) ch = gc();
  while (!isspace(ch) && ch != EOF) s[++top] = ch, ch = gc();
  s[top + 1] = '\0';
  return top;
}
template <typename tp>
inline void chemx(tp &a, tp b) {
  a = max(a, b);
}
template <typename tp>
inline void chemn(tp &a, tp b) {
  a = min(a, b);
}
const int N = 200005, M = 8;
int n, m, e[M][M], it[M], fir[M], cnt[M];
inline int getid() {
  static char s[M];
  return readstring(s);
}
inline bool check() {
  for (int s = 0; s < (1 << m) - 1; s++) {
    int l1 = 0, l2 = 0;
    for (int i = 0; i < m; i++)
      if (s & (1 << i)) l1 += cnt[i + 1];
    for (int i = 0; i < m; i++)
      for (int j = i; j < m; j++)
        if ((s & (1 << j)) | (s & (1 << i))) l2 += e[i + 1][j + 1];
    if (l1 > l2) return 0;
  }
  return 1;
}
int main() {
  n = read();
  int x = n;
  while (x) x /= 10, m++;
  for (int i = 1; i < n; i++) {
    int u = getid(), v = getid();
    e[u][v]++;
    if (u != v) e[v][u]++;
  }
  int pw = 10;
  for (int i = 1; i <= m; i++, pw *= 10)
    cnt[i] = pw - pw / 10, fir[i] = pw / 10;
  cnt[m] = n - pw / 100 + 1;
  if (check() == 0) return puts("-1"), 0;
  int ecnt = 0;
  cnt[1]--, it[1] = 1, fir[1]++;
  vector<pair<int, int> > ans;
  while (ecnt < n - 1) {
    for (int i = 1; i <= m; i++)
      if (it[i])
        for (int j = 1; j <= m; j++)
          if (e[i][j] && cnt[j]) {
            e[i][j]--, cnt[j]--;
            if (i != j) e[j][i]--;
            if (check()) {
              ans.push_back(pair<int, int>(fir[i] - 1, fir[j])), fir[j]++,
                  it[j] = 1, ecnt++;
            } else {
              e[i][j]++, cnt[j]++;
              if (i != j) e[j][i]++;
            }
          }
  }
  for (pair<int, int> x : ans) cout << x.first << " " << x.second << '\n';
  return 0;
}
