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("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


struct Sol{
  vector<vector<int>> d,d2;
  vector<int> vis;
  int buduj_las(int v,int par){
    debug("buduj_las",v, par);
    vis[v] = 1;
    int wyn = 0;
    for(int el:d[v])if(el != par){
      if(vis[el] == 1){
        wyn ++;
      }else if(vis[el] == 0){
        int pom = buduj_las(el,v);
        if(pom == 0){
          d2[v].PB(el);
          d2[el].PB(v);
          debug("w lesie ", v, el);
        }
        wyn += pom;
      }else
        wyn--;
    }
    vis[v] = 2;
    return wyn;
  }
  vector<PII> res;
  int dfs(int v, int par){
    vis[v] = 1;
    vector<int> x;
    vector<int> y;
    for(int el:d2[v])if(el != par){
      if(SZ(d2[el]) >= 2){
        int pom = dfs(el, v);
        if(pom != -1){
          x.PB(pom);
        }else{
          y.PB(el);
        }
      }else{
        y.PB(el);
      }
    }
    if(SZ(d2[v]) % 2 == 1 && SZ(y) != 0){
      y.pop_back();
    }
    for(int el:y)x.PB(el);
    for(int i = 0; i + 1 < SZ(x);i+=2){
      res.PB({x[i],x[i+1]});
    }
    if(SZ(x) & 1){
      return x.back();
    }else{
      return -1;
    }
  }
  void run(){
    int n,m;
    cin >> n >> m;
    if(n == 0)exit(0);
    d.resize(n);
    R(i,m){
      int pom, ost;
      cin >> pom >> ost;ost--;
      R(_,pom-1){
        int ak;
        cin >> ak;ak--;
        d[ak].PB(ost);
        d[ost].PB(ak);
        debug(ak,ost);
        ost = ak;
      }
    }
    vis.resize(n);
    d2.resize(n);
    buduj_las(0, -1);
    R(i,n)vis[i] = 0;
    R(i,n)if(SZ(d2[i]) >= 2 && !vis[i]){
      int pom = dfs(i, -1);
      if(pom != -1)res.PB({pom, i});
    }
    cout << SZ(res) << "\n";
    for(PII el:res){
      cout << el.FI + 1 << " " << el.SE + 1 << "\n";
    }
    
  }
};

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  while(1){
    Sol sol;
    sol.run();
  }
}