Problem Statement
You are given N−1 subsets of 1,2,...,N. Let the i-th set be Ei.
Let us choose two distinct elements ui and vi from each set Ei, and consider a graph T with N vertices and N−1 edges, whose vertex set is 1,2,..,N and whose edge set is (u1,v1),(u2,v2),...,(uN−1,vN−1). Determine if T can be a tree by properly deciding ui and vi. If it can, additionally find one instance of (u1,v1),(u2,v2),...,(uN−1,vN−1) such that T is actually a tree.
Constraints
- 2leqNleq105
- Ei is a subset of 1,2,..,N.
- ∣Ei∣geq2
- The sum of ∣Ei∣ is at most 2times105.
Input is given from Standard Input in the following format:
N
c1 w1,1 w1,2 ... w1,c1
:
cN−1 wN−1,1 wN−1,2 ... wN−1,cN−1
Here, ci stands for the number of elements in Ei, and wi,1,...,wi,ci are the ci elements in ci. Here, 2leqcileqN, 1leqwi,jleqN, and wi,jneqwi,k (1leqj<kleqci) hold.
Output
If T cannot be a tree, print -1
; otherwise, print the choices of (ui,vi) that satisfy the condition, in the following format:
u1 v1
:
uN−1 vN−1
Sample Output 1
Sample Output 2
Sample Output 3