Problem: There was no problem about a cactus at the NERC 2020 online round. That's a bad mistake, so judges decided to fix it. You shall not pass to the World Finals 2021 without solving a problem about a cactus!

A cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. Multiedges (multiple edges between a pair of vertices) and loops (edges that connect a vertex to itself) are not allowed in a cactus. 

Cher has got a cactus. She calls cactus strong if it is impossible to add an edge to it in such a way that it still remains a cactus. But Cher thinks her cactus is not strong enough. She wants to add the smallest possible number of edges to it to make it strong, i. e. to create a new cactus with the same vertices, so that the original cactus is a subgraph of the new one, and it is impossible to add another edge to it so that the graph remains a cactus. Cher hired you to do this job for her. So... it's on you!

Input

The input consists of one or more independent test cases.

The first line of each test case contains two integers n and m (1 ≤ n ≤ 10^5, 0 ≤ m ≤ 10^5), where n is the number of vertices in the graph. Vertices are numbered from 1 to n. Edges of the graph are represented by a set of edge-distinct paths, where m is the number of such paths. 

Each of the following m lines contains a path in the graph. A path starts with an integer number s_i (2 ≤ s_i ≤ 1000) followed by s_i integers from 1 to n. These s_i integers represent vertices of a path. Adjacent vertices in a path are distinct. The path can go through the same vertex multiple times, but every edge is traversed exactly once in the whole test case. There are no multiedges in the graph (there is at most one edge between any two vertices).

The last line of the input after all test cases always contains two zeros. It does not define a test case. It just marks the end of the input and does not require any output.

All graphs in the input are cacti. The total sum of all values of n and the total sum of all values of m throughout the input both do not exceed 10^5.

Output

For each test case, first output the line with the minimal possible number of additional edges A. Then output A lines, each describing one edge as u_i v_i, where u_i and v_i are the numbers of vertices to connect. After adding these edges, the resulting graph must be a strong cactus.

Example

Input


6 1
7 1 2 5 6 2 3 4
3 1
4 1 2 3 1
5 2
3 1 3 5
3 1 2 4
7 2
6 1 2 3 4 5 3
3 6 5 7
0 0


Output


1
1 4
0
1
5 4
2
1 3
6 7

Solution (in CPP):

Solution:
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
using ll = long long;
using ld = long double;
ll MOD = 998244353;
const ll root = 3;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
int n, m;
vector<int> adj[mxN];
int fd[mxN];
bool mark[mxN];
int getlow[mxN];
int par[mxN];
bool vis[mxN];
int bck[mxN];
vector<ttgl> res;
void dfs(int u) {
    vis[u] = 1;
    for(int v: adj[u]) {
        if(par[u]==v)continue;
        if(vis[v]==0) {
            par[v] = u;
            dfs(v);
        }else if(bck[v]!=u){
            bck[u] = v;
        }
    }
}
void dfsans(int u, int p = -1) {
    vis[u] = 1;
    if(mark[u]) {
        vector<int> curr;
        vector<int> leaves;
        for(int v: adj[u]) {
            if(!vis[v]) {
                dfsans(v, u);
                if(!mark[v]) {
                    if(getlow[v]!=-1) {
                        curr.senpai(getlow[v]);
                    }else leaves.senpai(v);
                }
            }
        }
        while(curr.size() > 1) {
            int f = curr.back();
            curr.pop_back();
            res.senpai({f, curr.back()});
            curr.pop_back();
        }
        if(curr.size() > 0) {
            if(leaves.size() > 0) {
                res.senpai({curr.back(), leaves.back()});
                leaves.pop_back();
            }else res.senpai({curr.back(), u});
        }
        while(leaves.size() > 1) {
            int f = leaves.back();
            leaves.pop_back();
            res.senpai({f, leaves.back()});
            leaves.pop_back();
        }
        getlow[u] = -1;
    }else {
        vector<int> curr;
        vector<int> leaves;
        for(int v: adj[u]) {
            if(!vis[v]) {
                dfsans(v, u);
                if(!mark[v]) {
                    if(getlow[v]!=-1) {
                        curr.senpai(getlow[v]);
                    }else leaves.senpai(v);
                }
            }
        }
        while(curr.size() > 1) {
            int f = curr.back();
            curr.pop_back();
            res.senpai({f, curr.back()});
            curr.pop_back();
        }
        if(curr.size() > 0) {
            getlow[u] = curr.back();
        }
        while(leaves.size() > 2) {
            int f = leaves.back();
            leaves.pop_back();
            res.senpai({f, leaves.back()});
            leaves.pop_back();
        }
        if(getlow[u]==-1 && leaves.size() > 0) {
            getlow[u] = leaves.back();
        }else if(getlow[u]!=-1 && leaves.size() > 1) {
            int f = leaves.back();
            leaves.pop_back();
            res.senpai({f, leaves.back()});
            leaves.pop_back();
        }
    }
}
void solve() {
    res.clear();
    owo(i, 0, n) {
        vis[i] = 0;
        par[i] = bck[i] = getlow[i] = -1;
        mark[i] = 0;
        fd[i] = i;
        adj[i].clear();
    }
    owo(i, 0, m) {
        int a, b, c;
        cin>>a>>b;
        owo(j, 1, a) {
            cin>>c;
            adj[b-1].senpai(c-1);
            adj[c-1].senpai(b-1);
            swap(b, c);
        }
    }
    dfs(0);
    owo(i, 0, n) {
        if(bck[i]!=-1) {
            mark[i] = 1;
            while(par[i]!=bck[i]) {
                mark[par[i]] = 1;
                fd[par[i]] = i;
                par[i] = par[par[i]];
            }
            fd[par[i]] = i;
        }
    }
    owo(i, 0 ,n) {
        vis[i] = 0;
    }
    mark[0] = 1;
    dfsans(0);
    cout<<res.size()<<"\n";
    for(auto p: res) {
        cout<<p.first+1<<" "<<p.second+1<<"\n";
    }
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    while(1) {
        cin>>n>>m;
        if(n==0 && m==0)exit(0);
        solve();
    }
    return 0;
}