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 SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define loop(i, a) for (int i = 0; i < (a); ++i)
#define cont(i, a) for (int i = 1; i <= (a); ++i)
#define circ(i, a, b) for (int i = (a); i <= (b); ++i)
#define range(i, a, b, c) for (int i = (a); (c) > 0 ? i <= (b) : i >= (b); i += (c))
#define parse(it, x) for (auto &it : (x))
#define pub push_back
#define pob pop_back
#define emb emplace_back
#define mak make_pair
#define mkt make_tuple
typedef long long ll;
typedef long double lf;
const int Inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;

int n, m;
vector<int> nei[100005], son[100005];
int lgl[100005];
int ban[100005], fa[100005];
int dp[100005][2], frm[100005];

void dfs(int now, int lst) {
	fa[now] = lst; lgl[now] = 1;
	parse(to, nei[now]) {
		if (to == lst) continue;
		if (lgl[to]) {
			if (lgl[to] != 1) continue;
			for (int i = now; i != to; i = fa[i]) ban[i] = 1;
		} else {
			dfs(to, now);
			son[now].pub(to);
		}
	}
	lgl[now] = 2;
}

void dft(int now) {
	dp[now][0] = 0, dp[now][1] = Inf;
	int ups = 0;
	parse(to, son[now]) {
		dft(to); if (!ban[to]) ++ups;
		dp[now][1] = min(dp[now][0] + dp[to][1], dp[now][1] + dp[to][0]);
		dp[now][0] += dp[to][0];
	}
	int pip = dp[now][0] - (ups >> 1);
	if (ban[now]) {
		dp[now][0] = min(pip, dp[now][1] - ((ups - 1) >> 1));
		if (dp[now][0] != pip) frm[now] = 1;
		else frm[now] = 0;
		dp[now][1] = Inf;
	} else {
		int res = dp[now][0] - ((ups - 1) >> 1);
		dp[now][0] = min(res, dp[now][1] - ((ups - 2) >> 1));
		if (dp[now][0] != res) frm[now] = 1;
		else frm[now] = 0;
		dp[now][1] = pip;
	}
}

void dfu(int now, int tp) {
	if (tp) {
		parse(to, son[now]) dfu(to, 0);
		return;
	}
	int sel = -1;
	parse(to, son[now]) {
		if (ban[to] == 1) continue;
		if (frm[now] && (!~sel || dp[sel][1] - dp[sel][0] > dp[to][1] - dp[to][0])) sel = to;
	}
	parse(to, son[now]) {
		if (sel == to) ban[to] = 2;
		dfu(to, ban[to] == 2);
	}
}

int up[100005];
vector<pair<int, int> > ans;

void dfv(int now) {
	up[now] = -1;
	parse(to, son[now]) {
		dfv(to);
		if (~up[to]) {
			if (~up[now]) ans.pub(mak(up[now], up[to])), up[now] = -1;
			else up[now] = up[to];
		}
	}
	if (!~up[now] && !ban[now]) up[now] = now;
	if (~up[now] && ban[now]) {
		ans.pub(mak(up[now], fa[up[now]] == now ? fa[now] : now));
		up[now] = -1;
	}
}

void solve() {
	cont(i, n) nei[i].clear(), son[i].clear();
	cont(i, n) lgl[i] = 0, ban[i] = 0;
	cont(i, m) {
		int l; scanf("%d", &l);
		int lst = 0;
		while (l--) {
			int now; scanf("%d", &now);
			if (lst) nei[lst].pub(now), nei[now].pub(lst);
			lst = now;
		}
	}
	dfs(1, 0); ban[1] = 1; dft(1);
	dfu(1, 0); ans.clear(); dfv(1);
	// assert(SZ(ans) == dp[1][0]);
	printf("%d\n", SZ(ans));
	parse(it, ans) printf("%d %d\n", it.first, it.second);
}

int main() {
	while(scanf("%d%d", &n, &m) && n) solve();
	return 0;
}