#include <cstdio>
#include <cassert>

#include "testlib.h"

using namespace std;

int s[100005];

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);
    
	int add = atoi(argv[1]);
	int sz = atoi(argv[2]);
	int disp = atoi(argv[3]);
	int k = add / sz;
	assert(k > 0);
	
	int n;
	scanf("%d", &n);
	printf("%d\n", n + add);
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		printf("%d %d\n", a, b);
	}
	int sum = 0;
	for (int i = 0; i < k - 1; i++)
	{
		s[i] = sz + rnd.next(2 * disp + 1) - disp;
		if (s[i] < 1) s[i] = 1;
		sum += s[i];
	}
	assert(sum < add);
	s[k - 1] = add - sum;
	int vn = n;
	for (int i = 0; i < k; i++)
	{
		int x = rnd.next(n);
		for (int j = 0; j < s[i]; j++)
		{
			printf("%d %d\n", x + 1, vn++ + 1);
		}
	}
	return 0;
}
