#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > adjacent, tadj;
int main() {
  int m, n;
  int pos[1001], num[1001];
  while (scanf("%d %d", &m, &n) != EOF) {
    adjacent.assign(m, vector<pair<int, int> >());
    tadj.assign(n, vector<pair<int, int> >());
    for (int i = 0; i < m; i++) {
      int nbr;
      scanf("%d", &nbr);
      for (int j = 0; j < nbr; j++) {
        scanf("%d", &pos[j]);
      }
      for (int j = 0; j < nbr; j++) {
        scanf("%d", &num[j]);
      }
      for (int j = 0; j < nbr; j++) {
        adjacent[i].push_back(pair<int, int>(pos[j] - 1, num[j]));
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < (int)adjacent[i].size(); j++) {
        pair<int, int> v = adjacent[i][j];
        tadj[v.first].push_back(pair<int, int>(i, v.second));
      }
    }
    printf("%d %d\n", n, m);
    for (int i = 0; i < n; i++) {
      printf("%d", tadj[i].size());
      for (int j = 0; j < (int)tadj[i].size(); j++) {
        printf(" %d", tadj[i][j].first + 1);
      }
      printf("\n");
      for (int j = 0; j < (int)tadj[i].size(); j++) {
        printf("%d", tadj[i][j].second);
        if (j < (int)tadj[i].size() - 1) printf(" ");
      }
      printf("\n");
    }
  }
  return 0;
}
