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

public class Generator {
	
	public final static int MAXN = 100000;
	public final static int MINN = 3;

	private final Random r;

	class DSS {
		int[] p;
		int[] s;
		int n;

		public DSS(int n) {
			this.n = n;
			p = new int[n];
			s = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = i;
				s[i] = 1;
			}
		}

		public boolean join(int x, int y) {
			x = get(x);
			y = get(y);
			if (x == y) {
				return false;
			}		
			if (s[x] > s[y]) {
				p[y] = x;
				s[x] += s[y];
			} else {
				p[x] = y;
				s[y] += s[x];
			}
			return true;
		}

		private int get(int x) {
			if (p[x] == x) {
				return x;
			}
			int res = get(p[x]);
			p[x] = res;
			return res;
		}

	}

	class Test {
		int n;
		int[][] edge;

		public Test(int n) {
			this.n = n;
			edge = new int[n - 1][2];
			DSS dss = new DSS(n);
			for (int i = 0; i < n - 1; i++) {
				int u = r.nextInt(n);
				int v = r.nextInt(n);
				while (!dss.join(u, v)) {
					u = r.nextInt(n);
					v = r.nextInt(n);
				}	
				edge[i][0] = u;
				edge[i][1] = v;
			}
		}

		public void writeTest(File file) throws IOException {
			PrintWriter out = new PrintWriter(file);
			out.println(n);
			for (int i = 0; i < n - 1; i++) {
				out.println((edge[i][0] + 1) + " " + (edge[i][1] + 1));
			}
			System.out.println("Test " + file.getName() + " generated.");
			out.close();
		}

	}



	public Generator(int randseed) {
		r = new Random(randseed);
	}

	private String numberToFilename(int tNum) {
		String res = Integer.toString(tNum);
		while (res.length() < 2) {
			res = "0" + res;
		}
		return res;
	}

	public void genTests(int testCount, int tNum) throws IOException {
		for (int i = 0; i < 9; i++) {
			new Test(MAXN).writeTest(new File(numberToFilename(tNum++)));	
		}
		for (int i = 0; i < testCount - 9; i++) {
			new Test(1 + r.nextInt(MAXN)).writeTest(new File(numberToFilename(tNum++)));	
		}	
	}

	public static void main(String[] args) throws IOException {
		if (args.length != 3) {
			System.out.println("usage java Generator <randseed> <testscount> <first-test-number>");
			System.exit(0);
		}
		new Generator(Integer.parseInt(args[0])).genTests(Integer.parseInt(args[1]), Integer.parseInt(args[2]));	
	}

}