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

public class TestsGen {

	static int done = 0;
	static ArrayList<Integer> data = new ArrayList<Integer>();
	static final int MAX_VALUE = (int) 1e9;
    static final int MAXN = 1000;
    static final int MAXN2 = 800;

	static final Random rand = new Random(556668949239L);

	static void print(int k, int n) throws IOException {
		done++;
		System.err.println(done);
		PrintWriter out;
		if (done < 10)
			out = new PrintWriter("0" + String.valueOf(done));
		else
			out = new PrintWriter("" + String.valueOf(done));
		out.println(n + " " + k);
		for (int i = 0; i < k; i++) {
			for (int j = 1; j < n; j++)
				out.print(data.get(i * n + j - 1) + " ");
			out.println(data.get((i + 1) * n - 1));
		}
		data.clear();
		out.close();
	}

	static void genRand(int n, int k, int maxValue) throws IOException {
		int temp = Math.max((int)(maxValue / (n * k) - 1), (int)(1));
		data.add(1);
		for (int i = 0; i < n * k - 1; i++) {
			data.add(data.get(i) + rand.nextInt(temp) + 1);
		}
		Collections.shuffle(data, rand);
		print(k, n);
	}

	public static void main(String[] args) throws IOException {
		//n*n*k*k
        genRand(10, 10, 1000);
	genRand(50, 50, 1000000);
        genRand(30, 50, MAX_VALUE);
        genRand(50, 30, MAX_VALUE);
	genRand(70, 70, 100);
        genRand(100, 100, 100000);
        genRand(100, 99, MAX_VALUE);
        genRand(99, 100, MAX_VALUE);

        //n*n*k or k*n*n
	genRand(300, 300, MAX_VALUE);
        genRand(250, 300, MAX_VALUE);
        genRand(300, 250, MAX_VALUE);
        genRand(299, 299, 100);
		
        //n*k
	genRand(MAXN2, MAXN2, MAX_VALUE);
        genRand(MAXN2 + 150, MAXN2 + 150, 100);
        genRand(MAXN2, MAXN2 + 100, MAX_VALUE);
        genRand(MAXN2 + 100, MAXN2, MAX_VALUE);
        
        genRand(MAXN, MAXN2, MAX_VALUE);
        genRand(MAXN2, MAXN, MAX_VALUE);
        genRand(MAXN, MAXN, MAX_VALUE);
        genRand(MAXN - 100, MAXN - 100, 100);
	}
}
