#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

const int MIN_T  =  1;
const int MAX_T  =  1e4;
const int MIN_N  =  2;
const int MAX_N  =  2e5;
const int MIN_NI = -1e9;
const int MAX_NI =  1e9;

const int rnd_test_n = 60;

template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
	dest.insert(dest.end(), orig.begin(), orig.end());
}

string output_tc(int t, const vector<vector<int>> &nums) {
	ostringstream oss;
    oss << t << endl;
    for (int i = 0; i < nums.size(); i++) {
        oss << nums[i].size() << endl;
        for (int j = 0; j < nums[i].size(); j++) {
            if (j != 0) oss << " ";
            oss << nums[i][j];
        }
        oss << endl;
    }
	return oss.str();
}

vector<string> generate_sample_tests()
{
    vector<string> tests;
    tests.push_back(output_tc(2, {{1, 2}, {5, 5, 5, 5}}));
    return tests;
}


void populateArray(vector<int>&arr) {
    for (int i = 0; i < arr.size(); i++) {
        arr[i] = rnd.next(MIN_NI, MAX_NI);
    }
}

vector<vector<int>> generateRandomArrays(int n) {
    vector<vector<int>> arr(n);
    int sumSizes = rnd.next(2*n, MAX_N);
    for (int i = 0; i < n; i++) {
        int size = sumSizes/n;
        if (size & 1) size--;
        arr[i].resize(size);
        populateArray(arr[i]);
    }
    return arr;
}

string rnd_test(int i){
    int min_t = MIN_T;
    int max_t = MAX_T;
    
    if(i<rnd_test_n / 3){
        min_t = 50;
    }
    else if(i<rnd_test_n / 2){
        max_t = 2000;
    }

    int t = rnd.next(min_t, max_t);
    return(output_tc(t, generateRandomArrays(t)));
}

vector<string> generate_random_tests() { 
    vector<string> tests;
    for (int i = 0; i < rnd_test_n; i++){
        tests.push_back(rnd_test(i));
    } 
    return tests;
}

string extreme_test_1(){
    return (output_tc(MAX_T, generateRandomArrays(MAX_T)));
}

vector<string> generate_extreme_tests(){
    vector<string> tests;   
    tests.push_back(extreme_test_1());
    return tests;
}

int main(int argc, char *argv[]) {
	registerGen(argc, argv, 1);
	vector<string> tests;
	size_t test = 0;
    append(tests, generate_sample_tests());
	append(tests, generate_random_tests());
	append(tests, generate_extreme_tests());
	for (const auto &t : tests) {
		startTest(++test);
		cout << t;
	}
	return 0;
}