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;

using ll = long long;
const int inf = 1e9+10;
const ll inf_ll = 1e18+10;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define cmax(x, y) (x = max(x, y))
#define cmin(x, y) (x = min(x, y))

#ifndef LOCAL
#define debug(...) 0
#else
#include "../../debug.cpp"
#endif

struct bridges {

    vector<int> low, tin;
    vector<bool> bridge;
    vector<vector<pair<int, int>>> adj;
    int e = 0, t = 0;

    bridges(int n) : adj(n), low(n, -1), tin(n, -1) {}

    // add an undirected edge between i and j
    void edge(int i, int j) {
        adj[i].push_back({j, e});
        adj[j].push_back({i, e++});
        bridge.push_back(0);
    }

    void dfs(int i, int p) {
        low[i] = tin[i] = ++t;
        for (auto& [j, k] : adj[i])
            if (k != p) {
                if (low[j] == -1) {
                    dfs(j, k);
                    low[i] = min(low[i], low[j]);
                    if (low[j] > low[i])
                        bridge[k] = 1;
                } else
                    low[i] = min(low[i], tin[j]);
            }
    }

    // returns a component vector for biconnected components in O(V+E).
    vector<int> components() {
        vector<int> comp(adj.size(), -1), stk;
        for (int i = 0; i < adj.size(); i++)
            if (low[i] == -1)
                dfs(i, -1);
        int c = 0;
        for (int i = 0; i < adj.size(); i++)
            if (comp[i] == -1) {
                stk.push_back(i);
                while (!stk.empty()) {
                    int j = stk.back(); stk.pop_back();
                    comp[j] = c;
                    for (auto& [k, l] : adj[j])
                        if (comp[k] == -1 && !bridge[l])
                            stk.push_back(k);
                }
                c++;
            }
        return comp;
    }
};

vector<int> odd_v, deg, v;
vector<array<int, 2>> dp;
vector<vector<array<int, 2>>> odd_adj;

void dfs(int i) {
    odd_v[i] = 1;
    int max_diff = 0;
    for (auto& [j, t] : odd_adj[i]) {
        if (odd_v[j]) continue;
        dfs(j);
        dp[i][1] += dp[j][0];
        dp[i][0] += dp[j][0];
        cmax(max_diff, dp[j][1]-dp[j][0]+1);
    }
    dp[i][0] += max_diff;
}

void dfs2(int i, int k, int x) {
    debug(i, k, x);
    if (x || dp[i][1] >= dp[i][0]) {
        for (auto& [j, t] : odd_adj[i])
            if (j != k) dfs2(j, i, 0);
        return;
    }
    int b = -1;
    for (auto& [j, t] : odd_adj[i]) {
        if (j == k) continue;
        if (b == -1 || dp[j][1]-dp[j][0] > dp[b][1]-dp[b][0])
            b = j;
    }
    for (auto& [j, t] : odd_adj[i]) {
        if (j == k) continue;
        if (j == b) {
            dfs2(j, i, 1);
            deg[i]--, deg[j]--, v[t] = 1;
        } else
            dfs2(j, i, 0);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    while (1) {
        int n, m; cin >> n >> m;
        if (n == 0 && m == 0) exit(0);
        vector<array<int, 2>> e;
        while (m--) {
            int len; cin >> len;
            int p = -1;
            for (int i = 0; i < len; i++) {
                int x; cin >> x; x--;
                if (p != -1) e.pb({x, p});
                p = x;
            }
        }
        m = e.size();
        bridges br(n);
        for (auto& [x, y] : e)
            br.edge(x, y);
        auto c = br.components();
        vector<vector<array<int, 2>>> adj(n);
        odd_adj.assign(n, {});
        dp.assign(n, {0, 0});
        odd_v.assign(n, 0);
        deg.assign(n, 0);
        v.assign(n, 0);
        int t = 0;
        for (auto& [x, y] : e)
            if (c[x] != c[y]) {
                adj[x].pb({y, t});
                adj[y].pb({x, t});
                deg[x]++, deg[y]++;
                t++;
            }
        for (int x = 0; x < n; x++)
            for (auto& [y, j] : adj[x])
                if ((deg[x]&1) && (deg[y]&1)) {
                    debug(x, y, j);
                    odd_adj[x].pb({y, j});
                }
        debug(odd_adj);
        for (int i = 0; i < n; i++)
            if (!odd_v[i]) dfs(i), dfs2(i, i, 0);
        debug(v);
        vector<array<int, 2>> ans;
        for (int x = 0; x < n; x++) {
            if (deg[x]&1) {
                int i = x;
                while (1) {
                    while (!adj[i].empty() && v[adj[i].back()[1]])
                        adj[i].pop_back();
                    if (adj[i].empty()) break;
                    v[adj[i].back()[1]] = 1;
                    deg[i]--;
                    i = adj[i].back()[0];
                    deg[i]--;
                }
                ans.pb({i, x});
            }
        }
        cout << ans.size() << "\n";
        for (auto& [x, y] : ans) {
            cout << x+1 << " " << y+1 << "\n";
        }
    }
}