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"
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 100000
#define mod 1000000007
#define inf 0x3f3f3f3f
template<class T> bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

struct E {int u,v,mark;};
vi to[maxn+5];
vector<E> e;

int cnt[maxn+5];
int dep[maxn+5];
int deg[maxn+5];

void dfs(int now,int fe)
{
    for(auto i: to[now]) if(i!=fe)
    {
        int v=now^e[i].u^e[i].v;
        if(dep[v]==0) 
        {
            dep[v]=dep[now]+1;
            dfs(v,i);
            cnt[now]+=cnt[v];
        }
        else if(dep[v]<dep[now])
        {
            cnt[now]++;
            cnt[v]--;
            e[i].mark=1;
        }
    }
    if(cnt[now]>0) e[fe].mark=1;
}

int vis[maxn+5];
void pre(int now,int fe)
{
    vis[now]=1;
    for(auto i: to[now]) if(e[i].mark==0 && i!=fe) 
    {
        int v=now^e[i].u^e[i].v;
        pre(v,i);
    }
    if(fe==-1) return;
    int fa=now^e[fe].u^e[fe].v;
    if(deg[now]&1 && deg[fa]&1) e[fe].mark=1,deg[now]--,deg[fa]--;
}

vector<pii> ans;
vi ret[maxn+5];
int match(int now,int fe)
{
    vis[now]=1;
    for(auto i: to[now]) if(e[i].mark==0 && i!=fe) 
    {
        int v=now^e[i].u^e[i].v;
        ret[now].pb(match(v,i));
    }
    int res=now;
    if(ret[now].size()&1) res=ret[now].back(),ret[now].pop_back();
    while(ret[now].size())
    {
        int u=ret[now].back(); ret[now].pop_back();
        int v=ret[now].back(); ret[now].pop_back();
        ans.pb({u,v});
    }
    if(fe==-1 && res!=now)
    {
        ans.pb({res,now}); res=0;
    }
    return res;
}

int main()
{
    int n,m; while(~scanf("%d%d",&n,&m))
    {
        if(n==0) break;
        e.clear();
        rep(i,1,n) to[i].clear();
        rep(i,1,m)
        {
            int k; scanf("%d",&k); k--;
            int last; scanf("%d",&last);
            while(k--)
            {
                int x; scanf("%d",&x);
                to[last].pb(e.size());
                to[x].pb(e.size());
                e.pb({last,x,0});
                last=x;
            }
        }
        rep(i,1,n) dep[i]=0;
        rep(i,1,n) cnt[i]=0;
        dep[1]=1; dfs(1,-1);

        rep(i,1,n) deg[i]=0;
        for(auto [x,y,mark]: e) if(mark==0) deg[x]++, deg[y]++;
        rep(i,1,n) vis[i]=0;
        rep(i,1,n) if(vis[i]==0) pre(i,-1);
        
        rep(i,1,n) vis[i]=0;
        ans.clear();
        rep(i,1,n) if(vis[i]==0) match(i,-1);
        int N=ans.size();
        printf("%d\n",N);
        for(auto [x,y]: ans) printf("%d %d\n",x,y);
    }
    return 0;
}