#include <bits/stdc++.h>
using namespace std;
int main() {
  int l, c;
  cin >> l >> c;
  int id[c];
  int m[l][c];
  for (int i = 0; i < l; i++)
    for (int j = 0; j < c; j++) m[i][j] = 0;
  for (int i = 0; i < l; i++) {
    int n;
    cin >> n;
    if (n != 0) {
      for (int j = 0; j < n; j++) {
        cin >> id[j];
      }
      for (int j = 0; j < n; j++) {
        cin >> m[i][id[j] - 1];
      }
    } else {
      getchar();
    }
  }
  int m2[c][l];
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < c; j++) {
      m2[j][i] = m[i][j];
    }
  }
  cout << c << " " << l << "\n";
  int ind[l];
  for (int i = 0; i < c; i++) {
    int n = 0, k = 0;
    for (int j = 0; j < l; j++) {
      if (m2[i][j] != 0) {
        ind[k] = j;
        k++;
        n++;
      }
    }
    cout << n << " ";
    if (n != 0)
      for (int j = 0; j < k; j++) {
        cout << ind[j] + 1 << " ";
      }
    else
      cout << "\n";
    cout << "\n";
    for (int j = 0; j < l; j++) {
      if (m2[i][j] != 0) cout << m2[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
