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 optimize(3)
#include<bits/stdc++.h>
using namespace std;
struct front_star{
    int to,next;
}e[500050];
struct grp{
    int fp,sp;
}ans[500050];
front_star eg[500050];
int n,m,cnt=1,t=0,tot=0,all=0,root;
int head[100005],dfn[100005],low[100005],brg[500005],hd[100005],vis[100005],sz[100005],dep[100005],upt[100005];
inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
inline void addedge(int u,int v)
{
    cnt++;
    e[cnt].to=v;
    e[cnt].next=head[u];
    head[u]=cnt;
}
inline void adde(int u,int v)
{
    tot++;
    eg[tot].to=v;
    eg[tot].next=hd[u];
    hd[u]=tot;
}
inline void tarjan(int x,int in_edge)
{
    t++;
    dfn[x]=low[x]=t;
    for(register int i=head[x];~i;i=e[i].next)
    {
        int y=e[i].to;
        if(!dfn[y])
        {
            tarjan(y,i);
            low[x]=min(low[x],low[y]);
            if(low[y]>dfn[x])
                brg[i]=brg[i^1]=1;
        }else if(i!=(in_edge^1))
            low[x]=min(low[x],dfn[y]);
    }
}
inline void dfs(int u,int fa)
{
    int spe=0;
    vis[u]=1;
    upt[u]=u;
    for(register int i=hd[u];~i;i=eg[i].next)
    {
        int v=eg[i].to;
        if(v==fa)
            continue;
        sz[u]++;
        if(!vis[v])
        {
            dep[v]=dep[u]+1;
            dfs(v,u);
            if(v==upt[v])
                spe=v;
        }
    }
    int pt=0,num=sz[u];
    if(u==root)
    {
        if(num%2==0)
        {
            for(register int i=hd[u];~i;i=eg[i].next)
            {
                int v=eg[i].to;
                if(v==fa)
                    continue;
                pt++;
                if(pt%2==1)
                {
                    all++;
                    ans[all].fp=upt[v];
                }
                else
                    ans[all].sp=upt[v];
            }
        }
        else
        {
            if(spe)
                num--;
            for(register int i=hd[u];~i;i=eg[i].next)
            {
                int v=eg[i].to;
                if(v==fa||v==spe)
                    continue;
                pt++;
                if(pt%2==1)
                {
                    all++;
                    ans[all].fp=upt[v];
                    if(pt==num)
                        ans[all].sp=u;
                }
                else
                    ans[all].sp=upt[v];
            }
        }
    }
    else
    {
        if(num%2==0)
        {
            if(spe)
                num--;
            for(register int i=hd[u];~i;i=eg[i].next)
            {
                int v=eg[i].to;
                if(v==fa||v==spe)
                    continue;
                pt++;
                if(pt%2==1)
                {
                    if(pt==num)
                    {
                        upt[u]=upt[v];
                        continue;
                    }
                    all++;
                    ans[all].fp=upt[v];
                }
                else
                    ans[all].sp=upt[v];
            }
        }
        else
        {
            for(register int i=hd[u];~i;i=eg[i].next)
            {
                int v=eg[i].to;
                if(v==fa)
                    continue;
                pt++;
                if(pt%2==1)
                {
                    if(pt==num)
                    {
                        upt[u]=upt[v];
                        continue;
                    }
                    all++;
                    ans[all].fp=upt[v];

                }
                else
                    ans[all].sp=upt[v];
            }
        }
    }
}
int main()
{
    memset(head,-1,sizeof(head));
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    memset(brg,0,sizeof(brg));
    memset(hd,-1,sizeof(hd));
    memset(vis,0,sizeof(vis));
    memset(sz,0,sizeof(sz));
    while(1)
    {
        t=0;
        cnt=1;
        tot=0;
        all=0;
        n=read();
        m=read();
        if(n==0&&m==0)
            break;
        for(register int i=1;i<=m;i++)
        {
            int s;
            s=read();
            int a,b;
            for(register int j=1;j<=s;j++)
            {
                a=read();
                if(j!=1)
                {
                    addedge(b,a);
                    addedge(a,b);
                }
                b=a;
            }
        }
        for(register int i=1;i<=n;i++)
        {
            if(!dfn[i])
                tarjan(i,0);
        }
        for(register int i=1;i<=n;i++)
            for(register int j=head[i];~j;j=e[j].next)
            {
                if(brg[j])
                    adde(i,e[j].to);
            }
        for(register int i=1;i<=n;i++)
        {
            if(!vis[i])
            {
                root=i;
                dep[i]=1;
                dfs(i,0);
            }
        }
        write(all);
        printf("\n");
        for(register int i=1;i<=all;i++)
        {
            write(ans[i].fp);
            printf(" ");
            write(ans[i].sp);
            printf("\n");
        }
        for(int i=1;i<=n;i++)
        {
            head[i]=-1;
            dfn[i]=0;
            low[i]=0;
            hd[i]=-1;
            vis[i]=0;
            sz[i]=0;
        }
        for(int i=1;i<=cnt+1;i++)
            brg[i]=0;
    }
    return 0;
}