// Arup Guha
// 6/18/2014
// Solution to 2003 World Finals Problem D: Eurodiffusion

import java.util.*;

public class euro {

	public static int day;
	public static int n;

	public static int[] dx = {0,-1,1,0};
	public static int[] dy = {-1,0,0,1};

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		int loop = 1;

		// Go through each case.
		while (n != 0) {

			country[] list = new country[n];
			city[][] grid = new city[11][11];
			for (int i=0; i<11; i++) Arrays.fill(grid[i], null);

			// Read stuff.
			for (int i=0; i<n; i++) {
				String s = stdin.next();
				int x1 = stdin.nextInt();
				int y1 = stdin.nextInt();
				int x2 = stdin.nextInt();
				int y2 = stdin.nextInt();
				list[i] = new country(s, x1, y1, x2, y2);
				init(grid, list[i], i, n);
			}

			// Annoying special case.
			if (n == 1) day = 0;
			else day = 1;

			// Simulate.
			while (!done(list)) {
				grid = updateCoins(grid);
				updateStatus(grid, list);
				day++;
			}

			// Sort and print.
			Arrays.sort(list);
			System.out.println("Case Number "+loop);
			for (int i=0; i<n; i++)
				System.out.println(list[i]);

			// Go to next case.
			loop++;
			n = stdin.nextInt();
		}
	}

	public static void updateStatus(city[][] grid, country[] list) {

		// First update completion dates per city, then check if countries are complete.
		for (int i=0; i<n; i++) {
			list[i].update(grid, day);
			list[i].updateComplete();
		}
	}

	public static city[][] updateCoins(city[][] grid) {

		// Store a new copy for the next day.
		city[][] next = new city[11][11];
		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {
				if (grid[i][j] == null) next[i][j] = null;
				else next[i][j] = new city(n, i, j);
			}
		}

		// Go through the whole grid.
		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {
				if (grid[i][j] != null) {

					// Calculate coins that go to neighbors.
					int[] move = new int[n];
					for (int k=0; k<n; k++)
						move[k] = grid[i][j].coins[k]/1000;

					// Move coins to neighbors.
					int numNeighbors = 0;
					for (int k=0; k<dx.length; k++) {
						int myx = i+dx[k];
						int myy = j+dy[k];
						if (inbounds(myx, myy) && grid[myx][myy] != null) {
							numNeighbors++;
							for (int z=0; z<n; z++)
								next[myx][myy].coins[z] += move[z];
						}
					}

					// Update coins left for you.
					for (int k=0; k<n; k++)
						next[i][j].coins[k] += (grid[i][j].coins[k] - numNeighbors*move[k]);
				}
			}
		}

		return next;
	}

	// Basic inbounds function.
	public static boolean inbounds(int x, int y) {
		return 0 <= x && x < 11 && 0 <= y && y < 11;
	}

	// Initialize the city grid based on this country which has the given index.
	public static void init(city[][] grid, country usa, int index, int numCountries) {
		for (int i=usa.startx; i<=usa.endx; i++)
			for (int j=usa.starty; j<=usa.endy; j++)
				grid[i][j] = new city(numCountries, i, j, index);
	}

	// Returns true iff all countries are done.
	public static boolean done(country[] list) {
		for (int i=0; i<n; i++)
			if (!list[i].isComplete())
				return false;
		return true;
	}
}

class city {

	public int n;
	public int x;
	public int y;
	public int[] coins;

	// Initial constructor for day 0.
	public city(int numCountries, int myx, int myy, int myCountry) {
		n = numCountries;
		x = myx;
		y = myy;
		coins = new int[n];
		coins[myCountry] = 1000000;
	}

	// Constructor for non-initial day. coins added later.
	public city(int numCountries, int myx, int myy) {
		n = numCountries;
		x = myx;
		y = myy;
		coins = new int[n];
	}

	// Returns true iff this city is done.
	public boolean done() {
		for (int i=0; i<n; i++)
			if (coins[i] == 0)
				return false;
		return true;
	}


}

class country implements Comparable<country> {

	final public static int NOTDONE = 1000000000;
	public String name;
	public int startx;
	public int starty;
	public int endx;
	public int endy;
	public int[][] done;
	public int complete;

	// Set up a country.
	public country(String s, int x1, int y1, int x2, int y2) {
		name = s;
		startx = x1;
		starty = y1;
		endx = x2;
		endy = y2;
		done = new int[endx-startx+1][endy-starty+1];
		for (int i=0; i<done.length; i++)
			Arrays.fill(done[i], -1);
		complete = NOTDONE;
	}

	// Check if all cities are complete in this country and if so, set complete.
	public void updateComplete() {

		// Look at each city.
		int max = 0;
		for (int i=0; i<done.length; i++) {
			for (int j=0; j<done[0].length; j++) {

				if (done[i][j] == -1) return;
				else max = Math.max(max, done[i][j]);
			}
		}

		// If we get here, we update.
		complete = max;
	}

	public void update(city[][] grid, int day) {

		// If we weren't done before, but we are done now, this is the day we completed.
		for (int i=0; i<done.length; i++)
			for (int j=0; j<done[0].length; j++)
				if (done[i][j] == -1 && grid[startx+i][starty+j].done())
					done[i][j] = day;
	}

	public boolean isComplete() {
		return complete < NOTDONE;
	}

	// How they want us to sort.
	public int compareTo(country other) {

		if (this.complete != other.complete)
			return this.complete - other.complete;

		return this.name.toLowerCase().compareTo(other.name.toLowerCase());
	}

	// How they want us to output a country.
	public String toString() {
		return "   "+name+"   "+complete;
	}

}