#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<vector>
#include<algorithm>
#define infile "zzid.in"
#define tmax 100

using namespace std;

struct test
{
  int h, w;
  int bricks;
} t[tmax];
int nr; //tests number

inline int randomValue(int a, int b)
{
  return (rand()%(b-a+1)) + a;
}

string makeString(int x)
{
  if(!x) return "0";
  string str;
  while(x)
    str = char((x%10) + '0') + str, x /= 10;
  return str;
}

void init()
{
  nr=20;
  t[1].h=10;        t[1].w=50;              t[1].bricks = 31;
  t[2].h=100;       t[2].w=20;              t[2].bricks = 131;
  t[3].h=75;        t[3].w=750;             t[3].bricks = 313;
  t[4].h=850;       t[4].w=125;             t[4].bricks = 1000;
  t[5].h=890;       t[5].w=890;             t[5].bricks = 2000;
  t[6].h=999;       t[6].w=999;             t[6].bricks = 3000;
  t[7].h=1000;      t[7].w=100*1000;        t[7].bricks = 4000;
  t[8].h=1000;      t[8].w=100*1000;        t[8].bricks = 5000;
  t[9].h=1000;      t[9].w=1000*1000;       t[9].bricks = 1000*1000;
  t[10].h=1000;     t[10].w=1000*1000;      t[10].bricks = 1000*1000;
  t[11].h=10*1000;  t[11].w=10*1000*1000;   t[11].bricks = 1000*1000;
  t[12].h=20*1000;  t[12].w=10*1000*1000;   t[12].bricks = 1000*1000;
  t[13].h=30*1000;  t[13].w=100*1000*1000;  t[13].bricks = 1000*1000;
  t[14].h=40*1000;  t[14].w=100*1000*1000;  t[14].bricks = 1000*1000;
  t[15].h=50*1000;  t[15].w=1000*1000*1000; t[15].bricks = 1000*1000;
  t[16].h=60*1000;  t[16].w=1000*1000*1000; t[16].bricks = 1000*1000;
  t[17].h=70*1000;  t[17].w=1000*1000*1000; t[17].bricks = 1000*1000;
  t[18].h=80*1000;  t[18].w=1000*1000*1000; t[18].bricks = 1000*1000;
  t[19].h=90*1000;  t[19].w=1000*1000*1000; t[19].bricks = 1000*1000;
  t[20].h=100*1000; t[20].w=1000*1000*1000; t[20].bricks = 1000*1000;
}

void generate(struct test t, int nr)
{ //generate test number nr
  string file = makeString(nr) + "-" + infile;
  freopen(file.c_str(), "w", stdout);

  printf("%d %d\n", t.h, t.w);
  int bricksLeft = t.bricks;

  for (int i = 0; i < t.h; ++i) {
      int n = randomValue(1, bricksLeft / (t.h - i));
      int widthLeft = t.w;
      vector <int> v;

      if (i + 1 == t.h) {
          n = bricksLeft;
      }

      bricksLeft -= n;
      printf("%d ", n);

      for (int j = 0; j < n; ++j) {
          int x = randomValue(1, widthLeft / (n - j));
          if (j + 1 == n) {
              x = widthLeft;
          }
          widthLeft -= x;
          v.push_back(x);
      }

      random_shuffle(v.begin(), v.end());

      for (size_t i = 0; i < v.size(); ++i) {
          printf("%d ", v[i]);
      }

      printf("\n");
  }

  fclose(stdout);
}

int main()
{
  srand((unsigned)time(0));
  init();

  for(int i = 1; i <= nr; ++i)
    generate(t[i],i);

  return 0;
}
