#include<stdio.h>
#include<queue>
using namespace std;

queue <int> q[110], r[110], ans[110];
int main(){
	int n, m, i, j, a, b, s=0;
	scanf("%d", &n);
	scanf("%d", &m);
	for(i=1; i<=n; i++){
		scanf("%d", &a);
		for(j=0;j<a;j++){
			scanf("%d", &b);
			q[i].push(b);
		}
	}
	for(i=1; i<=n; i++){
		r[q[i].front()].push(i);
		q[i].pop();
	}
	while(s<m){
		s = 0;
			queue <int> temp[110];
			for(i=1; i<=m; i++){
				if(r[i].empty()) s++;
				else{
					a = r[i].front();
					r[i].pop();
					if(!q[a].empty()){
						temp[q[a].front()].push(a);
						q[a].pop();
					}
					ans[i].push(a);
				}
			}
			for(i=1; i<=m; i++){
                while(!temp[i].empty()){
                    r[i].push(temp[i].front());
                    temp[i].pop();
                }
			}
	}
	for(i=1;i<=m;i++){
		printf("%d ", ans[i].size());
		while(!ans[i].empty()){
			printf("%d ", ans[i].front());
			ans[i].pop();
		}
		printf("\n");
	}
}
