#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;

vector<PII> E[10010];
int match[10010];
int vis[10010];
int c0, c1;

int find(int u)
{
	vis[u] = 1;
	for (int i = 0; i < E[u].size(); i++) {
		int v = E[u][i].first;
		if (vis[v]) continue;
		vis[v] = 1;
		if (match[v] == 0 || find(match[v])) {
			match[v] = u;
			match[u] = v;
			return 1;
		}
	}
	return 0;
}

int gao()
{
	int res = 0;
	memset(match, 0, sizeof(match));
	for (int i = 1; i <= c0; i++) {
		memset(vis, 0, sizeof(vis));
		if (find(i)) res++;
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(false);
	freopen("heavy.in", "r", stdin);
	freopen("heavy.out", "w", stdout);
	int n, m;
	while (cin >> n >> m) {
		string str;
		c0 = c1 = 0;
		for (int i = 0; i <= n + n; i++) E[i].clear();
		map<string, int> S, T; 
		for (int i = 1; i <= n; i++) {
			cin >> str;
			string A, B;
			for (int j = 0; j < m; j++) {
				A += str[j];
				B += str[str.size() - 1 - j];
			}
			if (!S.count(A)) S[A] = ++c0;
			if (!T.count(B)) T[B] = ++c1;
			int u = S[A], v = T[B];
			E[u].push_back(PII(v + n, i));
			E[v + n].push_back(PII(u, i));
		}
		int cnt = gao();
		printf("%d\n", cnt);
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= c0; i++) {
			if (!match[i]) find(i);
		}
		vector<int> U;
		for (int i = 1; i <= c0; i++) {
			if (!vis[i]) U.push_back(i);
		}
		for (int i = n + 1; i <= n + c1; i++) {
			if (vis[i]) U.push_back(i);
		}
		map<int, int> v;
		for (int i = 0; i < U.size(); i++) {
			int u = U[i];
			vector<int> Q;
			for (int j = 0; j < E[u].size(); j++) {
				int now = E[u][j].second;
				if (v.count(now)) continue;
				v[now] = 1;
				Q.push_back(now);
			}
			printf("%d", Q.size());
			for (int j = 0; j < Q.size(); j++) {
				printf(" %d", Q[j]);
			}
			puts("");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}


