Good Bye 2015
H
New Year and Forgotten Tree
Codeforces
3200
原题
← G→
翻译中…

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.

翻译中…

样例

Input #1
12
? ?
? ?
? ?
? ??
?? ?
?? ??
? ??
? ?
? ?
? ?
? ?
Output #1
3 1
1 6
9 1
2 10
1 7
8 1
1 4
1 10
5 1
10 11
12 1
InputCopy OutputCopy
Input #2
12
?? ??
? ?
? ?
? ??
?? ?
?? ??
? ??
? ?
? ?
?? ??
? ?
Output #2
-1
InputCopy OutputCopy
题目信息
题号
611H
所属比赛
时间限制
7 s
内存限制
256 MB
标签
构造
网络流
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。