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:
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+7;
struct{
    int l,r,flag;}Bian[N*2];
int fa[N],dep[N];
int du[N];
int getfa(int x){
    if (x==fa[x]) return x;
    return fa[x]=getfa(fa[x]);}
void merge(int x,int y){fa[fa[x]]=fa[y];}
vector<pair<int,int>> Si[N];
vector<int> si[N];
vector<pair<int,int>> ans;
int SIcnt;
int faFr[N];
void add(int l,int r){
    Bian[++SIcnt]={l,r,0};}
void add(int l,int r,int Whi){
    Si[l].push_back(make_pair(Whi,r));
    Si[r].push_back(make_pair(Whi,l));}
void dfs(int x){
    for (int i=0;i<Si[x].size();i++)
    if (dep[Si[x][i].second]==0)
    {
        int p=Si[x][i].second;
        fa[p]=x;
        dep[p]=dep[x]+1;
        faFr[p]=Si[x][i].first;
        dfs(p);
    }
}
void qing(int x,int y){
    if (dep[x]<dep[y]) swap(x,y);
    while (dep[x]>dep[y])
    {
        Bian[faFr[x]].flag=0;
        x=fa[x];
    }
    while (x!=y)
    {
        Bian[faFr[x]].flag=0;
        x=fa[x];
        Bian[faFr[y]].flag=0;
        y=fa[y];
    }
}       
int dfsQ(int x){
    int last=-1;
    for (int i=0;i<si[x].size();i++)
    {
        int p=si[x][i];
        if (fa[p]==0)
        {
            fa[p]=x;
            int pks=dfsQ(p);
            if (pks!=-1)
            {
                if (last==-1)
                    last=pks;
                else
                {
                    ans.push_back(make_pair(last,pks));
                    last=-1;
                }     
            }
        }
    }
    if (last!=-1)
        if (du[x]&1)
        { ans.push_back(make_pair(x,last));du[x]++;last=-1;}        
    if (fa[x]!=x)
    if (du[x]&1 && du[fa[x]]&1) du[x]++,du[fa[x]]++;
    if (du[x]&1) return x;
    return last;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    while (n||m)
    {
        ans.clear();
        for (int i=1;i<=n;i++) si[i].clear();
        for (int i=1;i<=n;i++) Si[i].clear();
        for (int i=1;i<=n;i++) fa[i]=i;
        for (int i=1;i<=n;i++) du[i]=0;
        for (int i=1;i<=n;i++) dep[i]=0;
        for (int i=1;i<=n;i++) faFr[i]=0;
        SIcnt=0;
        while (m--)
        {
            int cnt,last;
            scanf("%d",&cnt);
            scanf("%d",&last);
            for (int i=2;i<=cnt;i++)
            {
                int x;
                scanf("%d",&x);
                add(x,last);
                last=x;
            }
        }
        for (int i=1;i<=n;i++) fa[i]=i;
        for (int i=1;i<=SIcnt;i++)
        if (getfa(Bian[i].l)!=getfa(Bian[i].r))
        {
            Bian[i].flag=1;
            merge(Bian[i].l,Bian[i].r);
            add(Bian[i].l,Bian[i].r,i);
        }
        for (int i=1;i<=n;i++) fa[i]=0;
        fa[1]=1;
        dep[1]=1;
        dfs(1);
        for (int i=1;i<=SIcnt;i++)
        if (Bian[i].flag==0)
            qing(Bian[i].l,Bian[i].r);
        for (int i=1;i<=n;i++) fa[i]=0;
        for (int i=1;i<=SIcnt;i++)
        if (Bian[i].flag==1)
        {
            si[Bian[i].l].push_back(Bian[i].r);
            si[Bian[i].r].push_back(Bian[i].l);
            du[Bian[i].l]++;
            du[Bian[i].r]++;
        }
        for (int i=1;i<=n;i++)
        if (fa[i]==0)
        {
            fa[i]=i;
            int Q=dfsQ(i);
            if (Q!=-1 && Q!=i && fa[Q]!=i)
            ans.push_back(make_pair(i,Q));
        }        
        printf("%d\n",ans.size());
        for (int i=0;i<ans.size();i++)
            printf("%d %d\n",ans[i].first,ans[i].second);
        scanf("%d%d",&n,&m);
    }
}