#include "testlib.h"
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>


typedef long long ll;
typedef long double ld;

using namespace std;

int main(int argc, char **argv) {
	registerGen(argc, argv, 1);
	int gr = atoi(argv[1]);
	int n = atoi(argv[2]);
	int m = atoi(argv[3]);
	int q = atoi(argv[4]);
	int bl = atoi(argv[5]);
	assert(n == q);
	printf("%d ", gr);
	printf("%d %d\n", n, m);
	vector<int> vv;
	for (int i = 0; i < n; ++i)
		vv.push_back(rnd.next(0, m));
	sort(vv.begin(), vv.end());
	vector<int> vv2 = vv;
	for (int i = 0; i * bl < n; ++i) {
		int l = i * bl;
		int r = min(n, (i + 1) * bl);
		reverse(vv.begin() + l, vv.begin() + r);
	}
	for (int i = 0; i < n; ++i) {
		printf("%d", vv[i]);
		if (i != n - 1)
			printf(" ");
		else
			printf("\n");
	}
	printf("%d\n", q);
	if (gr == 1 || gr == 5 || gr == 2 || gr == 4) {
		for (int i = 0; i < n; ++i) {
			int x = i;
			printf("%d %d\n", x + 1, vv2[x]);
		}
	}
	else if (gr == 3) {
		for (int i = n - 1; i >= 0; --i) {
			int x = i;
			printf("%d %d\n", x + 1, vv2[x]);
		}
	}
	else
		assert(false);
	return 0;
}


