#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 a[510000];

int main(int argc, char **argv) {
	registerGen(argc, argv, 1);
	int k = atoi(argv[1]);
	int df = atoi(argv[2]);
	int gr, n, m, q;
	scanf("%d%d%d", &gr, &n, &m);
	assert(n >= 2);
	printf("%d %d %d\n", gr, n, m);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	for (int i = 0; i < k; ++i) {
		int x = rnd.next(0, n - 2);
		swap(a[x], a[x + 1]);
	}
	for (int i = 0; i < n; ++i) {
		printf("%d", a[i]);
		if (i != n - 1)
			printf(" ");
		else
			printf("\n");
	}
	scanf("%d", &q);
	printf("%d\n", q);
	for (int i = 0; i < q; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		y = y + rnd.next(-df, df);
		y = min(y, m);
		y = max(0, m);
		printf("%d %d\n", x, y);
	}
	return 0;
}


