#include <bits/stdc++.h>
using namespace std;
struct mat {
  int a, b;
};
int main() {
  int** t;
  int m, n, r;
  cin >> m >> n;
  t = new int*[m];
  for (int i = 0; i < m; i++) {
    t[i] = new int[n];
    for (int j = 0; j < n; j++) {
      t[i][j] = 0;
    }
    cin >> r;
    if (r != 0) {
      int* tab;
      tab = new int[r];
      for (int k = 0; k < r; k++) {
        cin >> tab[k];
      }
      for (int k = 0; k < r; k++) {
        cin >> t[i][tab[k] - 1];
      }
    } else {
      string c;
      getline(cin, c);
    }
  }
  cout << n << " " << m << endl;
  for (int i = 0; i < n; i++) {
    vector<mat> v;
    int nb = 0;
    for (int c = 0; c < m; c++) {
      if (t[c][i]) {
        nb++;
        mat x;
        x.a = c;
        x.b = t[c][i];
        v.push_back(x);
      }
    }
    cout << nb;
    if (nb != 0) {
      for (int u = 0; u < v.size(); u++) cout << " " << v[u].a + 1;
      cout << endl;
      for (int u = 0; u < v.size() - 1; u++) cout << v[u].b << " ";
      cout << v[v.size() - 1].b;
      cout << endl;
    } else {
      cout << endl << endl;
    }
  }
}
