import java.io.*;
import java.util.*;

public class TestGen {
	class Point implements Comparable<Point> {
	        int x, y;
	       
	        Point(int x, int y) {
	                this.x = x;
	                this.y = y;
	        }
	
	        public int compareTo(Point p) {
	                if (x != p.x) return x - p.x;
	                return y - p.y;
	        }
    }
	
	public static void main(String[] args) throws IOException {
		new TestGen().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int tNumber;
	Random rnd;
	final int MAXN = 99995; //10^5
	List<Integer>[] test;
	
	void print(List<Integer>[] al) throws IOException {
		System.err.println(tNumber);
		if (tNumber < 10) {
			out = new PrintWriter("../tests/0" + tNumber);
		} else {
			out = new PrintWriter("../tests/" + tNumber);
		}
		tNumber++;
		//out.println(al.length);
		out.println(al.length);
		for(int i = 0; i < al.length; i++){
			out.print(al[i].size());
			if(al[i].size() > 0)
				out.print(" ");
			for(int j = 0; j < al[i].size() - 1; j++)
				out.print((al[i].get(j) + 1) + " ");
			if(al[i].size() > 0)
				out.print((al[i].get(al[i].size() - 1) + 1));
			out.println();
		}
		out.close();
		for(int i = 0; i < al.length; i++)
			al[i].clear();
	}
	
	// here starts gens
	
	public void gen_sample1() throws IOException{
		int n = 4;
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		test[0].add(1);
		test[1].add(0);
		test[1].add(2);
		test[2].add(1);
		test[2].add(3);
		test[3].add(2);
		print(test);
	}
	
	public void gen_sample2() throws IOException{
		int n = 3;
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		test[0].add(1);
		test[0].add(2);
		test[1].add(2);
		test[1].add(0);
		test[2].add(0);
		test[2].add(1);
		print(test);
	}
	
	public void gen_good(int n) throws IOException{
		//System.err.println(n + "!");
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		int m = n / 2 + rnd.nextInt(n / 4);
		while(m >= n)
			m = n / 2 + rnd.nextInt(n / 4);
		//System.err.println(m + "!");
		int p[] = new int[n];
		for(int i = 0; i < n; i++)
			p[i] = i;
		shuffle(p);
		int i = 0, j = m;
		while(i < m && j < n){
			//System.err.println(i + " " + j);
			//test adding
			test[p[i]].add(p[j]);
			test[p[j]].add(p[i]);
			int newi = i + rnd.nextInt(2);
			int newj = j + rnd.nextInt(2);
			while(newi == i && newj == j){
				newi = i + rnd.nextInt(2);
				newj = j + rnd.nextInt(2);
			}
			i = newi;
			j = newj;
		}
		while(i < m){
			if(test[p[n - 1]].size() == 0 || test[p[n - 1]].get(test[p[n - 1]].size() - 1) != p[i]){
				test[p[i]].add(p[n - 1]);
				test[p[n - 1]].add(p[i]);
			}
			i++;
		}
		while(j < n){
			if(test[p[m - 1]].size() == 0 || test[p[m - 1]].get(test[p[m - 1]].size() - 1) != p[j]){
				test[p[j]].add(p[m - 1]);
				test[p[m - 1]].add(p[j]);
			}
			j++;
		}
		print(test);
		
	}
	
	public void gen_good_bad(int n) throws IOException{
		//System.err.println(n + "!");
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		int m = n / 2 + rnd.nextInt(n / 4);
		while(m >= n)
			m = n / 2 + rnd.nextInt(n / 4);
		//System.err.println(m + "!");
		int p[] = new int[n];
		for(int i = 0; i < n; i++)
			p[i] = i;
		shuffle(p);
		int i = 0, j = m;
		while(i < m && j < n){
			//System.err.println(i + " " + j);
			//test adding
			test[p[i]].add(p[j]);
			test[p[j]].add(p[i]);
			int newi = i + rnd.nextInt(2);
			int newj = j + rnd.nextInt(2);
			while(newi == i && newj == j){
				newi = i + rnd.nextInt(2);
				newj = j + rnd.nextInt(2);
			}
			i = newi;
			j = newj;
		}
		while(i < m){
			if(test[p[n - 1]].size() == 0 || test[p[n - 1]].get(test[p[n - 1]].size() - 1) != p[i]){
				test[p[i]].add(p[n - 1]);
				test[p[n - 1]].add(p[i]);
			}
			i++;
		}
		while(j < n){
			if(test[p[m - 1]].size() == 0 || test[p[m - 1]].get(test[p[m - 1]].size() - 1) != p[j]){
				test[p[j]].add(p[m - 1]);
				test[p[m - 1]].add(p[j]);
			}
			j++;
		}
		int q, w;
		q = rnd.nextInt(n);
		w = rnd.nextInt(n);
		while(w == q)
			w = rnd.nextInt(n);
		test[p[q]].add(p[w]);
		test[p[w]].add(p[q]);
		print(test);
		
	}
	
	public void gen_good_but_loop(int n) throws IOException{
		//System.err.println(n + "!");
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		int m = n / 2 + rnd.nextInt(n / 4);
		while(m >= n)
			m = n / 2 + rnd.nextInt(n / 4);
		//System.err.println(m + "!");
		int p[] = new int[n];
		for(int i = 0; i < n; i++)
			p[i] = i;
		shuffle(p);
		int i = 0, j = m;
		while(i < m && j < n){
			//System.err.println(i + " " + j);
			//test adding
			test[p[i]].add(p[j]);
			test[p[j]].add(p[i]);
			int newi = i + rnd.nextInt(2);
			int newj = j + rnd.nextInt(2);
			while(newi == i && newj == j){
				newi = i + rnd.nextInt(2);
				newj = j + rnd.nextInt(2);
			}
			i = newi;
			j = newj;
		}
		while(i < m){
			if(test[p[n - 1]].size() == 0 || test[p[n - 1]].get(test[p[n - 1]].size() - 1) != p[i]){
				test[p[i]].add(p[n - 1]);
				test[p[n - 1]].add(p[i]);
			}
			i++;
		}
		while(j < n){
			if(test[p[m - 1]].size() == 0 || test[p[m - 1]].get(test[p[m - 1]].size() - 1) != p[j]){
				test[p[j]].add(p[m - 1]);
				test[p[m - 1]].add(p[j]);
			}
			j++;
		}
		int q, w;
		q = rnd.nextInt(n);
		w = rnd.nextInt(n);
		while(w == q)
			w = rnd.nextInt(n);
		test[p[0]].add(p[n - 1]);
		test[p[n - 1]].add(p[0]);
		print(test);
		
	}
	
	public void gen_bad(int n) throws IOException{
		//System.err.println(n + "!");
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		TreeSet<Point> was = new TreeSet<Point>();
		int k = rnd.nextInt(n);
		for(int i = 0; i < n + k; i++){
			int x, y;
			x = rnd.nextInt(n);
			y = rnd.nextInt(n);
			while(x == y)
				x = rnd.nextInt(n);
			while(was.contains(new Point(x, y)) || was.contains(new Point(y, x))){
				x = rnd.nextInt(n);
				y = rnd.nextInt(n);
				while(x == y)
					x = rnd.nextInt(n);
			}
			was.add(new Point(x, y));
			was.add(new Point(y, x));
			test[x].add(y);
			test[y].add(x);
			//System.err.println(x + " " + y);
		}
		print(test);
	}
	
	public void gen_good1(int n) throws IOException{
		//System.err.println(n + "!");
		test = new ArrayList[n];
		for(int i = 0; i < n; i++)
			test[i] = new ArrayList<Integer>();
		int m = n / 2 + rnd.nextInt(n / 4);
		while(m >= n)
			m = n / 2 + rnd.nextInt(n / 4);
		//System.err.println(m + "!");
		int p[] = new int[n];
		for(int i = 0; i < n; i++)
			p[i] = i;
		shuffle(p);
		int i = 0, j = m;
		while(i < m && j < n){
			//System.err.println(i + " " + j);
			//test adding
			test[p[i]].add(p[j]);
			test[p[j]].add(p[i]);
			int newi = i + rnd.nextInt(2);
			int newj = j + rnd.nextInt(2);
			while(newi == i && newj == j){
				newi = i + rnd.nextInt(2);
				newj = j + rnd.nextInt(2);
			}
			i = newi;
			j = newj;
		}
		print(test);
	}
		//the end of the gens
	
	void shuffle(int[] a) {
		for (int i = 0; i < a.length; i++) {
			int j = rnd.nextInt(a.length);
			int tmp = a[j];
			a[j] = a[i];
			a[i] = tmp;
		}
	}

	public void generate() throws IOException {
		new File("../tests").mkdir();
		tNumber = 1;
		rnd = new Random(388282447);
	    gen_sample1();
	    gen_sample2();
	    for(int i = 10; i <= 50; i += 10) {
	    	gen_good(rnd.nextInt(i) + 5);
	    	gen_good_bad(rnd.nextInt(i) + 5);
	    	gen_good1(rnd.nextInt(i) + 5);
	    	gen_bad(rnd.nextInt(i) + 5);
	    }
	    gen_good_but_loop(100);
	    for(int i = 7; i <= 67; i += 10){
	    	rnd = new Random(i * i * i * i - 2);
	    	gen_good(rnd.nextInt(MAXN) + 5);
	    	gen_good_bad(rnd.nextInt(MAXN) + 5);
	    	gen_good1(rnd.nextInt(MAXN) + 5);
	    	gen_bad(rnd.nextInt(MAXN) + 5);
	    }
	    gen_good_but_loop(MAXN / 100);
	    System.err.println("MaXXXX time 1");
	    gen_good(MAXN + 5);
	    System.err.println("MaXXXX time 2");
    	gen_good_bad(MAXN + 5);
    	System.err.println("MaXXXX time 3");
    	gen_good1(MAXN + 5);
    	System.err.println("MaXXXX time 4");
    	gen_bad(MAXN + 5);
    	System.err.println("MaXXXX time 5");
    	gen_good_but_loop(MAXN + 5);
	}

	public void run() throws IOException {
		Locale.setDefault(Locale.US);
		generate();
	}
}
