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 = 100;
	ArrayList<Integer> test;
	
	
	void print(ArrayList 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.size());
		for (int i = 0; i < 3; i++) {
			out.print(al.get(i) + " ");
		}
		out.println(al.get(3));
		int n = 2 * (int)al.get(0);
		for (int i = 4; i < 4 + n; i += 2) {
			out.println(al.get(i) + " " + al.get(i + 1));
		}
		for (int i = 4 + n; i < al.size(); i += 3) {
			out.println(al.get(i) + " " + al.get(i + 1) + " " + al.get(i + 2));
		}
		out.close();
		al.clear();
	}
	
	// here starts gens
	
	void gen_sample() throws IOException {
	  test.add(3);
	  test.add(2);
	  test.add(6);
	  test.add(2);
	  //points
	  test.add(1);
	  test.add(5);
	  test.add(6);
	  test.add(2);
	  test.add(-2);
	  test.add(4);
	  test.add(5);
	  test.add(1);
	  test.add(2);
	  test.add(0);
	  test.add(4);
	  test.add(3);
	}
	
	void gen_stupid() throws IOException {
		test.add(1);
		test.add(1);
		test.add(1);
		test.add(1);
		test.add(1);
		test.add(0);
		test.add(1);
		test.add(1);
		test.add(1);
	}
	
	void gen_3pointer() throws IOException{
		test.add(2); test.add(2); test.add(6); test.add(1);
		test.add(0); test.add(6);
		test.add(4); test.add(4);
		test.add(0); test.add(7); test.add(3);
		test.add(4); test.add(3); test.add(2);
	}
	
	void gen_simple(int n, int mxc) throws IOException {
		test.add(n); test.add(n); test.add(rnd.nextInt(n/2) + 1); test.add(1);
		int a[] = new int[n];
		for(int i = 1; i <= n; i++) {
			a[i - 1] = rnd.nextInt(mxc + 1);
			test.add(a[i - 1]); test.add(i); 
		}
		for(int i = 1; i <= n; i++) {
			test.add(a[i - 1] + 1); test.add(i); test.add(rnd.nextInt(100) + 1); 
		}
	}
	
	void gen_max(int n, int mxc) throws IOException {
		if(n % 2 != 0)
			n++;
		if(mxc < n)
		  mxc = n + 5;
		test.add(n); test.add(n); test.add(1); test.add(mxc);
		for(int i = 0; i < n/2; i++) {
			test.add(-mxc + i); test.add(mxc);
			test.add(mxc - i); test.add(mxc);
		}
		for(int i = 0; i < n/2; i++) {
			test.add(-mxc + i); test.add(1); test.add(100);
			test.add(mxc - i); test.add(1); test.add(100);
		}
		
	}
	
	void gen_stupid_random(int mxn, int mxc) throws IOException {
		int n = rnd.nextInt(mxn) + 1;
		int m = rnd.nextInt(mxn) + 1;
		int r = rnd.nextInt(mxc) + 1;
		int l = rnd.nextInt(mxc) + 1;
		test.add(n); test.add(m); test.add(r); test.add(l);
		TreeSet<Point> was = new TreeSet<Point>();
		for(int i = 0; i < n + m; i++) {
			int x = rnd.nextInt(mxc) + 1;
			int y = rnd.nextInt(mxc) + 1;
			while(was.contains(new Point(x, y))) {
				x = rnd.nextInt(mxc) + 1;
				y = rnd.nextInt(mxc) + 1;	
			}
			was.add(new Point(x, y));
			test.add(x); test.add(y);
			if(i >= n)
				test.add(rnd.nextInt(100) + 1);
		}
	}
	
	void gen_max_random() throws IOException {
		int n = 1000;
		int m = 1000;
		int r = 100000; 
		int l = 100000;
		test.add(n); test.add(m); test.add(r); test.add(l);
		TreeSet<Point> was = new TreeSet<Point>();
		for(int i = 0; i < n + m; i++) {
			int x = rnd.nextInt(r) + 1;
			int y = rnd.nextInt(r) + 1;
			while(was.contains(new Point(x, y))) {
				x = rnd.nextInt(r) + 1;
				y = rnd.nextInt(r) + 1;	
			}
			was.add(new Point(x, y));
			test.add(x); test.add(y);
			if(i >= n)
				test.add(100);
		}
	}
	
	//the end of the gens
	

	public void generate() throws IOException {
		new File("../tests").mkdir();
		tNumber = 1;
		test = new ArrayList<Integer>();
		rnd = new Random(3282447);
		System.err.println("Working...");
		gen_sample();
		print(test);
		gen_stupid();
		print(test);
		gen_3pointer();
		print(test);
		gen_simple(4, 10);
		print(test);
		gen_stupid_random(2, 2);
		print(test);
		gen_max(10, 10);
		print(test);
		System.err.println("Don't panic! Working^^");
		for(int i = 0; i < 5; i++) {
			gen_simple((i + 1) * 10, (i + 1) * 1000);
			print(test);
			gen_stupid_random((i + 1) * 10, (i + 1) * 1000);
			print(test);
			gen_max((i + 1) * 10, (i + 1) * 1000);
			print(test);
		}
		for(int i = 0; i < 10; i++) {
			gen_simple((i + 1) * 100, (i + 1) * 10000);
			print(test);
			gen_stupid_random((i + 1) * 100, (i + 1) * 10000);
			print(test);
			gen_max((i + 1) * 100, (i + 1) * 10000);
			print(test);
		}
		
	    //time for MAXXXXTESTTTSSSS
		gen_simple(1000, 100000);
		print(test);
		gen_stupid_random(1000, 100000);
		print(test);
		gen_max(1000, 100000);
		print(test);
		for(int i = 0; i < 6; i++){
			gen_max_random();
			print(test);
		}
		
	}

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