#include <iostream.h>
#include <string>

main(){
  int m,n,r,val;
  cin >> m;
  cin >> n;
  while (m>0) {
    int outR[10001] = {0}; // These three variables store the output
    int outPos[10001][80]; // for the current instance.
    int outVal[10001][80];
    // First read the input instance and store it right away in the 
    // output variables 
    for (int i=1; i<=m; i++) { 
      cin >> r;
      int pos[1000];
      for (int j=1; j<=r; j++) {
	cin >> pos[j];
	outR[pos[j]]++;
	outPos[pos[j]][outR[pos[j]]] = i;
      }
      for (int j=1; j<=r; j++)
	cin >> outVal[pos[j]][outR[pos[j]]];
    }
    // Now print the output for the instance.
    cout << n << " " << m << "\n";
    for (int i=1; i<=n; i++) {
      cout << outR[i];
      for (int j=1; j<=outR[i]; j++)
	cout << " " << outPos[i][j];
      cout << "\n";
      for (int j=1; j<=outR[i]; j++)
	cout << (j==1 ? "" : " ") << outVal[i][j];
      cout << "\n";
    }
    cin >> m;
    cin >> n;
  }
}
