A tree is a connected undirected graph with n - 1 edges, where n denotes the number of vertices. Vertices are numbered 1 through n.

Limak is a little polar bear. His bear family prepares a New Year tree every year. One year ago their tree was more awesome than usually. Thus, they decided to prepare the same tree in the next year. Limak was responsible for remembering that tree.

It would be hard to remember a whole tree. Limak decided to describe it in his notebook instead. He took a pen and wrote n - 1 lines, each with two integers — indices of two vertices connected by an edge.

Now, the New Year is just around the corner and Limak is asked to reconstruct that tree. Of course, there is a problem. He was a very little bear a year ago, and he didn't know digits and the alphabet, so he just replaced each digit with a question mark — the only character he knew. That means, for any vertex index in his notes he knows only the number of digits in it. At least he knows there were no leading zeroes.

Limak doesn't want to disappoint everyone. Please, take his notes and reconstruct a New Year tree. Find any tree matching Limak's records and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1" (without the quotes).

Input

The first line contains a single integer n (2 ≤ n ≤ 200 000) — the number of vertices.

Each of the next n - 1 lines contains two space-separated non-empty strings, both consisting of questions marks only. No string has more characters than the number of digits in n.

Output

If there is no tree matching Limak's records, print the only line with "-1" (without the quotes).

Otherwise, describe any tree matching Limak's notes. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. You can print edges in any order.

Examples

Input

12
? ?
? ?
? ?
? ??
?? ?
?? ??
? ??
? ?
? ?
? ?
? ?


Output

3 1
1 6
9 1
2 10
1 7
8 1
1 4
1 10
5 1
10 11
12 1


Input

12
?? ??
? ?
? ?
? ??
?? ?
?? ??
? ??
? ?
? ?
?? ??
? ?


Output

-1
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 200010;
const int INF = 2147364800;
int N, tax[11], L[11], G[11][11], Nw[11], pw[11], all;
bool F[11];
vector<pair<int, int> > vec;
inline bool Hall() {
  for (int S = 1; S < (1 << all); S++) {
    int cntL = 0, cntR = 0;
    for (int i = 1; i <= all; i++)
      if (S & (1 << i - 1)) cntL += tax[i];
    for (int i = 1; i <= all; i++)
      for (int j = i; j <= all; j++)
        if ((S & (1 << i - 1)) || (S & (1 << j - 1))) cntR += G[i][j];
    if (cntL > cntR) return 0;
  }
  return 1;
}
inline int get(int x) {
  int cnt = 0;
  while (x) ++cnt, x /= 10;
  return cnt;
}
int main() {
  N = read();
  for (int i = 1; i < N; i++) {
    char str[11];
    int x, y;
    scanf("%s", str);
    x = strlen(str);
    scanf("%s", str);
    y = strlen(str);
    ++G[x][y];
    if (x != y) ++G[y][x];
  }
  for (int i = 0; i <= 10; i++) L[i] = INF;
  for (int i = 1; i <= N; i++) {
    int tmp = get(i);
    ++tax[tmp];
    all = max(all, tmp), L[tmp] = min(L[tmp], i);
  }
  for (int i = 1; i <= all; i++) Nw[i] = L[i];
  pw[1] = 1;
  for (int i = 2; i <= all; i++) pw[i] = pw[i - 1] * 10;
  --tax[1], F[1] = 1, ++Nw[1];
  int LK = 0;
  while (LK < N - 1) {
    bool flag = 0;
    for (int i = 1; i <= all; i++)
      if (F[i]) {
        for (int j = 1; j <= all; j++) {
          if (!G[i][j] || !tax[j]) continue;
          --tax[j], --G[i][j];
          if (i != j) --G[j][i];
          if (Hall()) {
            ++LK, F[j] = 1, flag = 1;
            vec.push_back(make_pair(pw[i], Nw[j]++));
          } else {
            ++tax[j], ++G[i][j];
            if (i != j) ++G[j][i];
          }
        }
      }
    if (!flag) {
      printf("-1\n");
      return 0;
    }
  }
  for (auto gg : vec) printf("%d %d\n", gg.first, gg.second);
  return 0;
}
