#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, fl = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - '0');
  return x * fl;
}
const int NN = 100000 + 17;
void open() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
}
void FAIL() {
  printf("-1\n");
  exit(0);
}
int n;
int ct[17], g[17][17], pw[17];
int maxs;
bool with_hall() {
  for (int s = 1; s < (1 << maxs); s++) {
    int cur = 0;
    for (int i = 1; i <= maxs; i++)
      if (s & (1 << i - 1)) cur += ct[i];
    for (int i = 1; i <= maxs; i++)
      for (int j = i; j <= maxs; j++)
        if ((s & (1 << i - 1)) && (s & (1 << j - 1))) {
          cur -= g[i][j];
        }
    if (cur <= 0) return 0;
  }
  return 1;
}
bool work() {
  for (int i = 1; i <= maxs; i++)
    for (int j = i; j <= maxs; j++) {
      if (g[i][j]) {
        if (ct[i] > 1) {
          ct[i]--, g[i][j]--;
          if (with_hall()) {
            printf("%d %d\n", pw[i] + ct[i], pw[j]);
            return 1;
          }
          ct[i]++, g[i][j]++;
        }
        if (ct[j] > 1) {
          ct[j]--, g[i][j]--;
          if (with_hall()) {
            printf("%d %d\n", pw[i], pw[j] + ct[j]);
            return 1;
          }
          ct[j]++, g[i][j]++;
        }
      }
    }
  return 0;
}
int bit_size(int x) {
  int res = 0;
  while (x) res++, x /= 10;
  return res;
}
void prework() {
  maxs = bit_size(n);
  for (int i = 1; i <= n; i++) ct[bit_size(i)]++;
  pw[1] = 1;
  for (int i = 2; i <= maxs; i++) pw[i] = pw[i - 1] * 10;
}
int get_len() {
  char str[17];
  scanf("%s", str + 1);
  return strlen(str + 1);
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = get_len(), y = get_len();
    if (x > y) swap(x, y);
    g[x][y]++;
  }
  prework();
  if (!with_hall()) FAIL();
  while (1) {
    bool ok = work();
    if (!ok) break;
  }
  for (int i = 1; i <= maxs; i++)
    for (int j = i + 1; j <= maxs; j++) {
      if (g[i][j]) {
        printf("%d %d\n", pw[i], pw[j]);
      }
    }
  return 0;
}
