#include <bits/stdc++.h>

using namespace std;

//const int MOD=1e9+7;
const int MOD=998244353;

const double PI=3.14159265359;

class Edge{
    public:
    int cap,flow,dest;
    bool inGraph;
    Edge *flEdgePair, *resEdgePair;
    Edge(int _dest, int _cap, bool ing, int _flow=0):dest(_dest),inGraph(ing),
    cap(_cap), flow(_flow){}
    
    void addFlow(int fl){
        cap-=fl;
        resEdgePair->cap+=fl;
        if(inGraph) flEdgePair->flow+=fl;
        else flEdgePair->flow-=fl;
    }
};

class Dinic{
    public:
    vector<vector<Edge*>> flow, res;
    vector<int> dists, preds;
    
    int S,n,T;
    Dinic(vector<vector<pair<int,int>>>& net):S(0), n(net.size()), T(n-1){
        flow.resize(n);
        res.resize(n);
        dists.resize(n);
        preds.resize(n);
		fill(preds.begin(), preds.end(),-1);
        
        for(int i=0; i<n; i++){
            for(auto p:net[i]){
                Edge* e1=new Edge(p.first, p.second, true);
                Edge* e2=new Edge(i, 0, false);
                Edge* e3=new Edge(p.first, p.second, true);
                
                e1->flEdgePair=e3;
                e2->flEdgePair=e3;
                e1->resEdgePair=e2;
                e2->resEdgePair=e1;
                flow[i].push_back(e3);
                res[i].push_back(e1);
                res[p.first].push_back(e2);
            }
        }
    }
    bool bfs(){
        fill(dists.begin(), dists.end(),-1);
        queue<int> q;
        q.push(S);
        dists[S]=0;
        while(q.size()){
            int cur=q.front();
            q.pop();
            for(auto e:res[cur]){
                if(e->cap && dists[e->dest]==-1){
                    dists[e->dest]=dists[cur]+1;
                    q.push(e->dest);
                }
            }
        }
        return dists[T]!=-1;
    }
    
    void dfs(){
        vector<int> ep(n);
        vector<bool> dead(n);
        while(!dead[S]){
            //vector<int> preds(n,-1);
            stack<int> st;
            st.push(0);
            while(st.size()){
                int cur=st.top();
                //cout<<cur<<endl;
                if(cur==T) break;
                while(ep[cur]<res[cur].size() && (dead[res[cur][ep[cur]]->dest] ||
                dists[res[cur][ep[cur]]->dest]!=dists[cur]+1 || 
                res[cur][ep[cur]]->cap==0)){
                    ep[cur]++;
                }
                if(ep[cur]==res[cur].size()){
                    dead[cur]=true;
                    st.pop();
                }
                else{
                    preds[res[cur][ep[cur]]->dest]=cur;
                    st.push(res[cur][ep[cur]]->dest);
                }
            }
            if(st.size() && st.top()==T){
                //cout<<st.size()<<endl;
                int flVal=1e9;
                int cur=T;
                while(cur!=S){
                    //cout<<cur<<endl;
                    cur=preds[cur];
                    flVal=min(flVal,res[cur][ep[cur]]->cap);
                }
                cur=T;
                while(cur!=S){
                    cur=preds[cur];
                    res[cur][ep[cur]]->addFlow(flVal);
                }
            }
            else{
                dead[S]=true;
            }
            
        }
        
    }
    
    vector<vector<Edge*>> maxflow(){
        //bfs();
        //dfs();
        while(bfs()){
            dfs();
        }
        return flow;
    }
    
    
};



int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<vector<int>> e(n);
    
    for(int i=1; i<n; i++){
        int t;
        cin>>t;
        e[i].resize(t);
        for(int& j:e[i]) cin>>j;
    }
    
    vector<vector<pair<int,int>>> net(2*n+1);
    for(int i=1; i<=n; i++){
        net[0].push_back({i,1});
    }
    for(int i=1; i<n; i++){
        net[n+i].push_back({2*n,1});
        for(int j:e[i]){
            net[j].push_back({i+n,1});
        }
    }
    /*
    for(int i=0; i<=2*n; i++){
        cout<<i<<":\n";
        for(auto p:net[i]){
            cout<<p.first<<' ';
        }
        cout<<'\n';
    }
    */
    
    Dinic din(net);
    auto f=din.maxflow();
    int fl=0;
    
    int start=-1;
    
    
    for(auto e:f[0]){
        fl+=e->flow;
        if(!(e->flow)) start=e->dest;
    }
    if(fl!=n-1){
        cout<<-1;
        //cout<<fl<<endl;
        return 0;
    }
    
    queue<int> q;
    q.push(start);
    vector<int> preds(2*n+1,-1);
    while(q.size()){
        int cur=q.front();
        q.pop();
        for(auto e:din.res[cur]){
            if(e->dest && e->cap && preds[e->dest]==-1){
                preds[e->dest]=cur;
                q.push(e->dest);
            }
        }
    }
    for(int i=n+1; i<2*n; i++){
        if(preds[i]==-1){
            cout<<-1;
            return 0;
        }
    }
    
    vector<int> ans1(n);
    for(int i=1; i<=n; i++){
        for(auto e:f[i]){
            if(e->flow){
                ans1[e->dest-n]=i;
            }
        }
    }
    
    for(int i=1; i<n; i++){
        cout<<ans1[i]<<' '<<preds[i+n]<<'\n';
    }
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 118260