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

public class TestGen {
	public static void main(String[] args) {
		new TestGen().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;
	Random rnd;
	int tNumber;

	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());
	}

	class Test {
		int n, m;
		ArrayList<Integer> a, b;

		public void genGoodTest(int N, int M, double s) throws IOException {
			n = N;
			m = M;
			b = new ArrayList<Integer>();
			b.add(1);
			for (int i = 1; i < m; i++) {
				b.add(b.get(i - 1) + rnd.nextInt(2 * i - b.get(i - 1)) + 1);
			}
			int t = 0;
			a = new ArrayList<Integer>();
			for (int i = 0; i < n; i++) {
				if ((rnd.nextDouble() < s) && (t < m - 1)) {
					t++;
				}
				if (rnd.nextDouble() < s) {
					a.add(b.get(t));
				} else
					a.add(rnd.nextInt(2 * n) + 1);
			}
			printTest();
		}
		
		public void genBadTest(int N, int M, double s) throws IOException {
			n = N;
			m = M;
			b = new ArrayList<Integer>();
			b.add(1);
			for (int i = 1; i < m; i++) {
				b.add(b.get(i - 1) + rnd.nextInt(2 * i - b.get(i - 1)) + 1);
			}
			int t = 0;
			a = new ArrayList<Integer>();
			for (int i = 0; i < n; i++) {
				if ((rnd.nextDouble() < s) && (t < m - 1)) {
					t++;
				}
				if (rnd.nextDouble() < s) {
					a.add(b.get(t));
				} else
					a.add(rnd.nextInt(2 * n) + 1);
			}
			Collections.shuffle(a, rnd);
			Collections.shuffle(b, rnd);
			printTest();
		}
		
		public void printTest() throws IOException {
			if (tNumber < 10)
				out = new PrintWriter("0" + tNumber);
			else
				out = new PrintWriter("" + tNumber);
			tNumber++;
			if (rnd.nextBoolean()) {
				int t = n;
				n = m;
				m = t;
				ArrayList<Integer> tmp = (ArrayList<Integer>) a.clone();
				a = (ArrayList<Integer>) b.clone();
				b = tmp;
			}
			out.println(n + " " + m);
			for (int i = 0; i < n; i++) {
				out.print(a.get(i));
				if (i < n - 1)
					out.print(" ");
			}
			out.println();
			for (int i = 0; i < m; i++) {
				out.print(b.get(i));
				if (i < m - 1)
					out.print(" ");
			}
			out.close();
		}
	}

	public void solve() throws IOException {
		rnd = new Random(31);
		tNumber = 1;
		Test t = new Test();
		
		t.genGoodTest(10, 10, 0.5);
		t.genGoodTest(80 + rnd.nextInt(20), 80 + rnd.nextInt(20), 0.8);
		t.genGoodTest(100, 100, 1);
		t.genGoodTest(80 + rnd.nextInt(20), 80 + rnd.nextInt(20), 0);
		t.genGoodTest(70 + rnd.nextInt(30), 70 + rnd.nextInt(30), 0.7);
		t.genGoodTest(70 + rnd.nextInt(30), 70 + rnd.nextInt(30), 0.3);
		
		t.genBadTest(100, 100, 0.9);
		t.genBadTest(80 + rnd.nextInt(20), 80 + rnd.nextInt(20), 0);
		t.genBadTest(70 + rnd.nextInt(30), 70 + rnd.nextInt(30), 0.7);
		t.genBadTest(70 + rnd.nextInt(30), 70 + rnd.nextInt(30), 0.3);
		
		t.genGoodTest(2000, 2000, 0.5);
		t.genGoodTest(4000 + rnd.nextInt(1000), 4000 + rnd.nextInt(1000), 0.8);
		t.genGoodTest(5000, 5000, 1);
		t.genGoodTest(4000 + rnd.nextInt(1000), 4000 + rnd.nextInt(1000), 0);
		t.genGoodTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.7);
		t.genGoodTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.3);
		t.genGoodTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.7);
		t.genGoodTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.3);
		t.genGoodTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.75);
		
		t.genBadTest(5000, 5000, 0.9);
		t.genBadTest(4000 + rnd.nextInt(1000), 4000 + rnd.nextInt(1000), 0);
		t.genBadTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.7);
		t.genBadTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.3);
		t.genBadTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.7);
		t.genBadTest(3500 + rnd.nextInt(1500), 3500 + rnd.nextInt(1500), 0.3);
		
		
	}

	public void run() {
		try {

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}