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;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) x&-x
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
#define Rint register int
#define ls (u<<1)
#define rs (u<<1|1)
typedef unsigned int unit;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD=1e9+7,mod=998244353;
ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
const int MAXN=5e5+10,MAXM=1e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int inv2=(MOD+1)/2;
const int Lim=1<<20;

int n,m;
Vi g[MAXN];

int head[MAXN],to[MAXN],_next[MAXN],ecnt=1;

void add_edge(int u,int v)
{
    _next[++ecnt]=head[u];
    to[ecnt]=v;
    head[u]=ecnt;
}

int dfn[MAXN],low[MAXN],tot,cut[MAXN];
bool cutedge[MAXM];

void tarjan(int u,int fa,int root)
{
    dfn[u]=low[u]=++tot;
    int ch=0;
    for(int i=head[u];i;i=_next[i])if(to[i]!=fa)
    {
        int v=to[i];
        if(!dfn[v])
        {
            tarjan(v,u,root);
            low[u]=min(low[u],low[v]);
            if(low[v]>=dfn[u]&&u!=root)cut[u]=1;
            if(low[v]>dfn[u])cutedge[i]=cutedge[i^1]=1;
            if(u==root)ch++;
        }
        low[u]=min(low[u],dfn[v]);
    }
    if(u==root&&ch>=2)cut[root]=1;
}


int cur[MAXN];
bool vis[MAXN];
bool sel[MAXN];
Vpii ans;
int dfs(int u)
{
    vis[u]=1;
    if(sel[u])cur[u]=u;
    for(auto v:g[u])if(!vis[v])
    {
        int p=dfs(v);
        if(p)
        {
            if(cur[u])ans.pb({p,cur[u]}),cur[u]=0;
            else cur[u]=p;
        }
    }
    return cur[u];
}

void dfs1(int u)
{
    vis[u]=1;
    for(auto v:g[u])if(!vis[v])
    {
        dfs1(v);
        if(sel[v]&&sel[u])sel[v]=sel[u]=0;
    }
}


void solve()
{
    ans.clear();
    for(int i=1;i<=ecnt;i++)
    {
        cutedge[i]=0;
    }
    tot=0;ecnt=1;
    for(int i=1;i<=n;i++)
    {
        head[i]=cut[i]=0;
        dfn[i]=low[i]=0;
        g[i].resize(0);
        cur[i]=vis[i]=sel[i]=0;
    }
    for(int i=1;i<=m;i++)
    {
        Vi vec;
        int p;R(p);
        while(p--)
        {
            int u;R(u);
            vec.pb(u);
        }
        for(int i=0;i<SZ(vec)-1;i++)
        {
            add_edge(vec[i],vec[i+1]);
            add_edge(vec[i+1],vec[i]);
        }
    }
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i,0,i);
    for(int i=1;i<=n;i++)
        for(int j=head[i];j;j=_next[j])if(cutedge[j])
        g[i].pb(to[j]);
    for(int i=1;i<=n;i++)
    {
        if(SZ(g[i])&1)sel[i]=1;
    }
    for(int u=1;u<=n;u++)if(!vis[u])
        dfs1(u);
    for(int i=1;i<=n;i++)vis[i]=0;
    for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
    W(SZ(ans));
    for(auto j:ans)W(j);
}

int main()
{
    srand(time(0));
    int T=1;
    //scanf("%d",&T);
    for(int kase=1;kase<=T;kase++)
    {
        //printf("Case #%d: ",kase);
        while(scanf("%d%d",&n,&m)==2&&(n||m))
        solve();
    }
    return 0;
}