#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, r;
  cin >> m >> n;
  int mat[n][m];
  int tab[n * m];
  for (int i = 0; i < m; i++) {
    cin >> r;
    if (r == 0) {
      for (int k = 0; k < n; k++) {
        mat[k][i] = 0;
      }
    } else {
      for (int j = 0; j < r; j++) {
        int ind;
        cin >> ind;
        tab[j] = ind;
      }
      for (int j = 0; j < n; j++) {
        int k = 0;
        if (j == tab[k] - 1) {
          int nb;
          cin >> nb;
          mat[j][i] = nb;
          k++;
        } else
          mat[j][i] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << mat[i][j] << endl;
  }
  cout << n << " " << m << endl;
  for (int i = 0; i < n; i++) {
    int compt = 0;
    for (int j = 0; j < m; j++) {
      if (mat[i][j] != 0) {
        compt++;
        tab[compt] = j + 1;
      }
    }
    if (compt != 0) {
      cout << compt;
      for (int k = 0; k < compt; k++) {
        cout << tab[k] << " ";
      }
      cout << endl;
      for (int k = 0; k < compt; k++) {
        cout << mat[i][tab[k] - 1] << " ";
      }
      cout << endl;
    } else
      cout << compt << endl << endl;
  }
  return 0;
}
