#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "testlib.h"
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;

int main(int argc, char* argv[]) {
  registerGen(argc, argv, 1);

  int t = opt<int>("t");
  int maxn = opt<int>("maxn");
  int dom = opt<int>("dom");

  struct Test {
    vector<int> p;
    vector<int> h;
  };

  vector<Test> tests;

  auto Print = [&]() {
    shuffle(tests.begin(), tests.end());
    cout << tests.size() << '\n';
    for (auto& test : tests) {
      int n = int(test.h.size());
      cout << n << '\n';
      for (int i = 0; i < n; i++) {
        cout << test.h[i] << " \n"[i == n - 1];
      }
      for (int i = 0; i < n; i++) {
        cout << test.p[i] << " \n"[i == n - 1];
      }
    }
    exit(0);
  };

  int cur_sum = 0;

  for (int lim = 1; ; lim++) {
    for (int n = 1; n <= lim; n++) {
      for (int w = 1; w <= lim; w++) {
        if (w < lim && n < lim) {
          continue;
        }
        Test test;
        test.p.resize(n);
        test.h.resize(n);
        auto Dfs = [&](auto&& self, int v) {
          if (v == 2 * n) {
            if (cur_sum + n > maxn || int(tests.size()) == t) {
              Print();
            }
            tests.push_back(test);
            cur_sum += n;
            return;
          }
          for (int val = 1; val <= w; val++) {
            if (v < n) test.p[v] = val; else {
              test.h[v - n] = val;
              if (dom && test.h[v - n] > test.p[v - n]) continue;
            }
            self(self, v + 1);
          }
        };
        Dfs(Dfs, 0);
      }
    }
  }

  return 0;
}