#include<bits/stdc++.h>
using namespace std;
//mt19937 rd(time(0)+(unsigned long long)(new int));
mt19937 rd(114514);
int Random(int l,int r){
	uniform_int_distribution<int> d(l,r);
	return d(rd);
}
constexpr int N=10000000;
int a[N+10],b[N+10],btop;
deque<int> q;
int main(){
	ofstream fout;
	int Tcnt=0;
	while(1){
		++Tcnt;
		fout.open("meow.in");
		int T=1000,iT=T;
		fout<<T<<'\n';
		while(T--){
			int n,m,K;
			n=300;
			K=Random(0,5);
			if(!K) K=n*2-2;
			else K=n*2-1;
			if(n==1) K=n*2-1;
			m=2000000/iT;
			fout<<n<<' '<<m<<' '<<K<<'\n';
			int tmp=(m>>1)-K;
			int i;
			for(i=1;i<=K;++i) a[i]=Random(0,tmp);
			assert(a[0]==0);
			sort(a+1,a+1+K);
			a[K]=tmp;
			for(i=K;i>=1;--i) a[i]-=a[i-1],++a[i];
			btop=0;
			if(n==1){
				for(i=1;i<=K;++i) for(int j=1;j<=a[i];++j) b[++btop]=i;
				shuffle(b+1,b+1+btop,rd);
				int top=0;
				q.clear();
				for(i=1;i<=m;++i){
					int op=Random(0,1);
					if(q.empty()) op=0;
					if(top==(m>>1)) op=1;
					if(!op){
						++top;
						fout<<b[top]<<' ';
						q.push_back(b[top]);
						continue;
					}
					else{
						fout<<q.back()<<' ';
						q.pop_back();
						continue;
					}
				}
				fout<<'\n';
				continue;
			}
			for(i=1;i<=K;++i) for(int j=1;j<=a[i]<<1;++j) b[++btop]=i;
			shuffle(b+1,b+1+btop,rd);
			for(i=1;i<=btop;++i) fout<<b[i]<<' ';
			fout<<'\n';
		}
		fout.close();
		system("./meow");
		if(system("./chk")) break;
		cerr<<"Success on test #"<<Tcnt<<'\n';
	}
}
