#include <stdio.h>

	struct Record
	{
		int start;
		int end;
		int freq;
	};
	void display(const struct Record *records, const struct Record *x_axis, const struct Record *y_axis, int length, int width);
	int count_digits(int n);

	int main(int argc, char *argv[])
	{
		struct Record x_axis, y_axis;
		int length, interval;
		scanf("%u %u %u %u\n", &x_axis.start, &x_axis.end, &y_axis.start, &y_axis.end);
		scanf("%u\n", &interval);
		scanf("%u\n", &length);
		int size = length / interval;
		struct Record records[size];
		int k = 0;
		int biggest_start = 0, biggest_end = 0;
		for(int i = 0; i < length; )
		{
			int a, b;
			struct Record current = {.start = 0, .end = 0, .freq = 0};
			for(int j = 0; j < interval; j++, i++)
			{
				scanf("%u %u\n", &a, &b);
				if(current.start == 0)
					current.start = a;
				current.freq += b;
			}
			current.end = a;
			//keeping track of the largest boundaries in order to estimate the width of the bars
			//eg : 132 and 1934 will give a width of 3 (132) + 4 (1934) + 1 (space inbetween the numbers) = 8
			if(current.start > biggest_start)
				biggest_start = current.start;
			if(current.end > biggest_end)
				biggest_end = current.end;
			current.freq /= interval;
			records[k++] = current;
		}
		display(records, &x_axis, &y_axis, size, count_digits(biggest_start) + count_digits(biggest_end) + 1);

		return 0;
	}

	void display(const struct Record *records, const struct Record *x_axis, const struct Record *y_axis, int length, int width)
	{
		int left_pad = count_digits(y_axis->end);
		for(int freq = y_axis->end; freq >= 1; freq--)
		{
			printf("%*d ", left_pad, freq);
			for(int i = 0; i < length; i++)
			{
				//http://stackoverflow.com/a/16299867/3729391
				if(records[i].freq >= freq)
					printf("%.*s ", width, "##########################");
				else
					printf("%.*s ", width, "                          ");
			}
			printf("\n");
		}
		printf("%*c ", left_pad, ' ');
		for(int i = 0; i < length; i++)
			printf("%d%*d ", records[i].start, width - count_digits(records[i].start), records[i].end);
	}

	int count_digits(int n)
	{
		if(n == 0)
			return 1;
		for(int i = 1, count = 0; ; i *= 10, count++)
			if(n / i == 0)
				return count;
	}