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 + 7;
const int N = 1e5;
vector<pair<int, int>> g[N];
int tag[N];
int dp[N][2]; // 0: no edge up, 1: edge up
int bestc[N];

int findCycles(int i, int p) {
	int res = tag[i];
	for (auto& pr : g[i]) {
		int t = pr.first;
		if (t == p) continue;

		if (tag[t] != -1) {
			pr.second = 1;
			res = min(res, tag[t]);
		} else {
			tag[t] = tag[i] + 1;
			int sub = findCycles(t, i);
			if (sub <= tag[i]) pr.second = 1;
			res = min(res, sub);
		}
	}
	if (res < tag[i]) {
		for (auto& pr : g[i]) {
			if (pr.first == p) pr.second = 1;
		}
	}
	return res;
}

void fillDP(int i, int p) {
	int cou = 0;
	dp[i][0] = 0;
	dp[i][1] = 0;
	bestc[i] = -1;

	pair<int, int> best = {0, -1};
	for (auto pr : g[i]) {
		int t = pr.first;
		if (pr.second || t == p) continue;
	
		++cou;
		fillDP(t, i);

		dp[i][0] += dp[t][1];
		best = min(best, {dp[t][0] - dp[t][1] - 1, t});
	}
	dp[i][0] += cou / 2;

	if (cou & 1) {
		if (p == -1) {
			dp[i][1] = dp[i][0] + best.first + 1;
			dp[i][0] = dp[i][0] + 1;
			bestc[i] = best.second;
		} else {
			dp[i][1] = dp[i][0];
			dp[i][0] = INF;
			bestc[i] = -1;
		}
	} else if (cou > 0) {
		dp[i][1] = dp[i][0] + best.first + (p == -1 && best.second != -1);
		bestc[i] = best.second;
	}
}

int recFill(int i, int p, bool eup, vector<pair<int, int>>& res) {
	int cur = -1;
	for (auto pr : g[i]) {
		int t = pr.first;
		if (pr.second || t == p) continue;

		if (eup && t == bestc[i]) recFill(t, i, 0, res);
		else {
			int sub = recFill(t, i, 1, res);
			if (cur != -1) {
				res.emplace_back(cur, sub);
				cur = -1;
			} else {
				cur = sub;
			}
		}
	}

	if (eup) {
		if (cur == -1) return i;
		else return cur;
	} else {
		if (cur != -1) res.emplace_back(i, cur);
		return -1;
	}
}

void solve() {
	int n, m;
	cin >> n >> m;
	if (n == 0 && m == 0) exit(0);

	for (int i = 0; i < n; ++i) {
		tag[i] = -1;
		dp[i][0] = -1;
	}

	for (int j = 0; j < m; ++j) {
		int s;
		cin >> s;
		int a = -1;
		for (int i = 0; i < s; ++i) {
			int b;
			cin >> b;
			--b;

			if (a != -1) {
				g[a].emplace_back(b, 0);
				g[b].emplace_back(a, 0);
			}
			a = b;
		}
	}

	tag[0] = 0;
	findCycles(0, -1);

	vector<pair<int, int>> res;
	for (int i = 0; i < n; ++i) {
		if (dp[i][0] != -1) continue;
		fillDP(i, -1);

		if (dp[i][1] < dp[i][0]) recFill(i, -1, 1, res);
		else recFill(i, -1, 0, res);
	}

	cout << res.size() << '\n';
	for (auto pr : res) cout << pr.first + 1 << ' ' << pr.second + 1<< '\n';

	for (int i = 0; i < n; ++i) {
		g[i].clear();
		g[i].shrink_to_fit();
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	while(true) solve();
}