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

public class gentests implements Runnable {
  public static void main(String[] args) {
    if (args.length < 1) {
      throw new Error("Not enough parameters");
    }
    L = Integer.parseInt(args[0]);
    new Thread(new gentests()).start();
  }
  
  PrintWriter out;
  Random rand = new Random(6082573165L);
  
  static int L,I;
  void open() {
    try {
      out = new PrintWriter(((I < 10) ? "0" : "") + I);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
  void close() {
    out.close();
    I++;
  }
  
  int rand(int l, int r) {
    return l + rand.nextInt(r - l + 1);
  }
  
  
  
  int[] getGray(int n) {
	  int m = 1 << n;
	  int[] ans = new int[m];
	  int shift = rand(0, m - 1);
	  for (int i = 0; i < m; i++) {
		  int ti = (i + shift) % m;
		  ans[i] = ti ^ (ti >> 1);
	  }
	  boolean[] u = new boolean[n];
	  int[] p = new int[n];
	  for (int i = 0; i < n; i++) {
		  int j = rand.nextInt(n - i) + 1;
		  int k = -1;
		  while (j > 0) {
			  k++;
			  if (!u[k]) j--;
		  }
		  u[k] = true;
		  p[i] = k;
	  }
	  
	  int[] trueAns = new int[m];
	  for (int i = 0; i < m; i++) {
		  for (int j = 0; j < n; j++) {
			  trueAns[i] += ((ans[i] >> p[j]) & 1) << j;
		  }
	  }
	  
	  return trueAns;
  }
  
  
  ArrayList<int[]> comeToGray(int[] per, int n) {
	  int m = 1 << n;
	  int[][] tans = new int[m - 1][2];
	  int[] permut = new int[m];
	  for (int i = 0; i < m; i++) permut[i] = i;
	  for (int i = 0; i < m; i++) {
		  int j = rand(i, m - 1);
		  int t = permut[i];
		  permut[i] = permut[j];
		  permut[j] = t;
	  }
	  int[] rev = new int[m];
	  for (int i = 0; i < m; i++) {
		  rev[per[i]] = i;
	  }
	  int[] gr = getGray(n);
	  int tm = 0;
	  for (int i = 0; i < m - 1; i++) {
		  int k = permut[i];
		  if (per[k] != gr[k]) {
			  tans[tm][0] = k;
			  tans[tm][1] = rev[gr[k]];
			  rev[per[k]] = rev[gr[k]];
			  rev[gr[k]] = k;
			  int t = per[tans[tm][0]];
			  per[tans[tm][0]] = per[tans[tm][1]];
			  per[tans[tm][1]] = t;
			  tm++;
		  }
	  }
	  ArrayList<int[]> ans = new ArrayList<int[]>();
	  for (int i = 0; i < tm; i++) {
		  ans.add(tans[i]);
	  }
	  return ans;
  }
  
  void genTest(int n, int m, double prob) {
	  open();
	  out.println(n);
	  int[] a = getGray(n);
	  for (int i = 0; i < 1 << n; i++) {
	  	  if (i > 0) {
	  	  	out.print(" ");
	  	  }
		  out.print(a[i]);
	  }
	  out.println();
	  out.println(m);
	  int w = 0;
	  while (w < m) {
		  double f = rand.nextDouble();
		  if (f <= prob) {
			  int i = rand(0, (1 << n) - 1);
			  int j = rand(0, (1 << n) - 2);
			  if (j >= i) j++;
			  out.println(i + " " + j);
			  int t = a[i];
			  a[i] = a[j];
			  a[j] = t;
			  w++;
		  } else {
			  ArrayList<int[]> ts = comeToGray(a, n);
			  int k = 0;
			  while (k < ts.size() && w < m) {
				  out.println(ts.get(k)[0] + " " + ts.get(k)[1]);
				  w++;
				  k++;
			  }
		  }
	  }
	  
	  close();
  }
  
  
  public void solve() throws IOException {
    I = L;
    genTest(1, 1, 0);
    for (int i = 1; i < 8; i++) {
   		genTest(2*i - 1, rand(1, 100000), 0.99);
   		genTest(2*i, rand(1, 100000), 0.1);
    }
    genTest(16, 100000, 0.999);
  }

  public void run() {
    try {
      solve();
    } catch (IOException e) {
    }
  }
}
