#include <stdio.h>

	struct Record
	{
		size_t start;
		size_t end;
		size_t freq;
	};
	void display(const struct Record *records, const struct Record *record_x, const struct Record *record_y, size_t length);
	size_t count_digits(size_t n);

	int main(int argc, char *argv[])
	{
		struct Record record_x, record_y;
		size_t length;
		scanf("%u %u %u %u\n", &record_x.start, &record_x.end, &record_y.start, &record_y.end);
		scanf("%u", &length);
		struct Record records[length];
		for(size_t i = 0; i < length; i++)
			scanf("%u %u %u\n", &records[i].start, &records[i].end, &records[i].freq);
		display(records, &record_x, &record_y, length);

		return 0;
	}

	void display(const struct Record *records, const struct Record *record_x, const struct Record *record_y, size_t length)
	{
		size_t left_pad = count_digits(record_y->end);
		for(size_t freq = record_y->end; freq >= record_y->start; freq--)
		{
			printf("%*u", left_pad, freq);
			for(size_t i = 0; i < length; i++)
			{
				printf("%*c", count_digits(records[i].start), ' ');
				printf("%c", records[i].freq >= freq ? '*' : ' ');
			}
			printf("\n");
		}
		printf("%*c", left_pad, ' ');
		for(size_t i = 0; i < length; i++)
			printf("%u ", records[i].start);
		printf("%u\n", records[length - 1].end);
	}

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