import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;


public class doAll_max {
	
	private static final int MAX_ELEMENT_VALUE = (int)1e4;
	private static final int maxn = 300;	
	
	class T {
		int n;
		int m;
		int[][] a;
		public T(int n, int m) {
			this.n = n;
			this.m = m;
			a = new int[n][m];
		}
		public T(T t) {
			this(t.n, t.m);
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					a[i][j] = t.a[i][j];
				}
			}
		}
		public void write(PrintWriter out) {
			out.println(n + " " + m);
			for (int i = 0; i < n; i++) {
				out.println(writeArray(a[i]));
			}			
		}
	}
	
	interface NumberGenerator {
		int next();
	}
	
	private String writeArray(int[] a) {
		return Arrays.toString(a).replaceAll("[\\[\\],]", "");
	}	
		
	public String twoDigits(int n) {
		return ((n < 10) ? "0" : "") + n;  
	}
	
	int testNumber = 1;
	
	public static void main(String[] args) throws IOException {		
		new doAll_max().doAll();
	}
	
	
	final NumberGenerator ngRandom = new NumberGenerator() {
		public int next() {				
			return srand(MAX_ELEMENT_VALUE);
		}			
	};
	
	class NGConst implements NumberGenerator {
		int value;

		public NGConst(int value) {		
			this.value = value;
		}

		public int next() {
			return value;
		}
	}
	
	class NGPeriod implements NumberGenerator {
		int period;
		int delta;
		int initial;				
		
		int current;
		
		public NGPeriod(int period, int delta, int initial) {		
			this.period = period;
			this.delta = delta;
			this.initial = initial;
			current = initial;
		}
		
		public NGPeriod(int period, int delta) {
			this(period, delta, 0);
		}

		public int next() {
			current++;
			if (current == period) {
				current = 0;
			}
			return current + delta;
		}
	}
	
	private void doAll() throws IOException {
		parsePredefined();

		T t = new T(2, 3);
		t.a[0][0] = 1;	
		t.a[0][1] = 1;	
		t.a[0][2] = 1;	
		t.a[1][0] = 1;	
		t.a[1][1] = 1;	
		t.a[1][2] = 1;
		writeTest(t);

		t = new T(5, 4);
		t.a[0] = new int[] {9, -2, -1, 3};
		t.a[1] = new int[] {-10, -5, 1, -4};
		t.a[2] = new int[] {1, -1, 2, -2};
		t.a[3] = new int[] {3, 0, 0, -1};
		t.a[4] = new int[] {2, 2, -1, 2};
		writeTest(t);
		
		writeTest(gen(4, 4, ngRandom));
		
		int[][] dimensions = new int[][]{{2, 2}, {maxn, maxn}, {2, maxn}, {maxn, 2}}; 
		for (int[] d: dimensions) {
			writeTest(gen(d, ngRandom));			
			writeTest(gen(d, new NGConst(-MAX_ELEMENT_VALUE)));
			writeTest(gen(d, new NGConst(MAX_ELEMENT_VALUE)));			
		}
		writeTest(gen(8, 8, new NGConst(0)));
		writeTest(gen(239, 261, new NGPeriod(7, -3, 4)));
		writeTest(gen(239, 261, new NGPeriod(19, -10, 15)));
		writeTest(gen(261, 239, new NGPeriod(19, -10, 15)));
		writeTest(gen(261, 268, new NGPeriod(239, -115, 18)));
		
		for (int i = 0; i < 5; i++) {
			int rmax = rand(10000);
			int delta = -(rand(rmax - 1) + 1);
			int start = rand(rmax);
			
			writeTest(gen(rand(maxn - 1) + 1, rand(maxn - 1) + 1, new NGPeriod(rmax, delta, start)));
		}
	}
	
	private T gen(int[] d, NumberGenerator ngRandom) {
		return gen(d[0], d[1], ngRandom);
	}

	private void parsePredefined() throws IOException {
		for (int i = 1; i < 100; i++) {
			File pt = new File("test" + twoDigits(i));
			if (pt.canRead()) {
				copyFile(pt, new File(twoDigits(i)));
				testNumber = i + 1;
			}
		}		
	}

	Random random = new Random(doAll_max.class.getName().hashCode());
	
	private int rand(int max) {
		return random.nextInt(max);
	}
	
	private int srand(int max) {
		return rand(2 * max + 1) - max; 
	}
	
	private void writeTest(T test) throws FileNotFoundException {
		PrintWriter out = new PrintWriter(twoDigits(testNumber++));
		try {
			test.write(out);
		} finally {
			out.close();
		}
	}
	
	private T gen(int n, int m, NumberGenerator g) {
		T t = new T(n, m);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				t.a[i][j] = g.next();
			}
		}
		return t;
	}
	
	private void copyFile(File fin, File fout) throws IOException {		
		BufferedReader in = new BufferedReader(new FileReader(fin));
		BufferedWriter out = new BufferedWriter(new FileWriter(fout));
		try {
			try {
				int c;
				while ((c = in.read()) != -1) {
					out.write(c);
				}
			} finally {
				in.close();
			}
		}
		finally {
			out.close();
		}
	}
}
