You were lucky enough to get a map just before entering the legendary magical mystery world. The map shows the whole area of your planned exploration, including several countries with complicated borders. The map is clearly drawn, but in sepia ink only; it is hard to recognize at a glance which region belongs to which country, and this might bring you into severe danger. You have decided to color the map before entering the area. “A good deal depends on preparation,” you talked to yourself.

Each country has one or more territories, each of which has a polygonal shape. Territories belonging to one country may or may not “touch” each other, i.e. there may be disconnected territories. All the territories belonging to the same country must be assigned the same color. You can assign the same color to more than one country, but, to avoid confusion, two countries “adjacent” to each other should be assigned different colors. Two countries are considered to be “adjacent” if any of their territories share a border of non-zero length.

Write a program that finds the least number of colors required to color the map.



Input

The input consists of multiple map data. Each map data starts with a line containing the total number of territories n, followed by the data for those territories. n is a positive integer not more than 100. The data for a territory with m vertices has the following format:


String
x1 y1
x2 y2
...
xm ym
-1


“String” (a sequence of alphanumerical characters) gives the name of the country it belongs to. A country name has at least one character and never has more than twenty. When a country has multiple territories, its name appears in each of them.

Remaining lines represent the vertices of the territory. A vertex data line has a pair of nonneg- ative integers which represent the x- and y-coordinates of a vertex. x- and y-coordinates are separated by a single space, and y-coordinate is immediately followed by a newline. Edges of the territory are obtained by connecting vertices given in two adjacent vertex data lines, and byconnecting vertices given in the last and the first vertex data lines. None of x- and y-coordinates exceeds 1000. Finally, -1 in a line marks the end of vertex data lines. The number of vertices m does not exceed 100.

You may assume that the contours of polygons are simple, i.e. they do not cross nor touch themselves. No two polygons share a region of non-zero area. The number of countries in a map does not exceed 10.

The last map data is followed by a line containing only a zero, marking the end of the input data.

Output

For each map data, output one line containing the least possible number of colors required to color the map satisfying the specified conditions.

Example

Input

6
Blizid
0 0
60 0
60 60
0 60
0 50
50 50
50 10
0 10
-1
Blizid
0 10
10 10
10 50
0 50
-1
Windom
10 10
50 10
40 20
20 20
20 40
10 50
-1
Accent
50 10
50 50
35 50
35 25
-1
Pilot
35 25
35 50
10 50
-1
Blizid
20 20
40 20
20 40
-1
4
A1234567890123456789
0 0
0 100
100 100
100 0
-1
B1234567890123456789
100 100
100 200
200 200
200 100
-1
C1234567890123456789
0 100
100 100
100 200
0 200
-1
D123456789012345678
100 0
100 100
200 100
200 0
-1
0


Output

4
2
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,ans,country_index;

bool adj_check[10][10];

#define NUM 9999999.0

struct Point{
	double x,y;
};

struct Data{
	Data(double arg_value,bool arg_is_i){
		value = arg_value;
		is_i = arg_is_i;
	}
	bool operator<(const struct Data &arg) const{
		return value < arg.value;
	};
	double value;
	bool is_i;
};

typedef Point Vector;

struct Segment{
	void set(double x1,double y1,double x2,double y2){
		p1.x = x1;
		p1.y = y1;
		p2.x = x2;
		p2.y = y2;
	}
	Point p1,p2;
};

typedef Segment Line;

struct Region{
	vector<Line> Lines;
};

struct Country{
	int color;
	char name[21];
	vector<Region> regions;
};

struct Shishimaru{
	int colors[10];
};


void recursive(Shishimaru shishimaru,int count){

	if(count == country_index){

		int tmp_max = 0;

		for(int i = 0; i < country_index; i++){
			tmp_max = max(tmp_max,shishimaru.colors[i]);
		}

		ans  = min(ans,tmp_max);

		return;
	}

	for(int i = 0; i < country_index; i++){
		if(shishimaru.colors[i] != -1)continue;

		bool check[11];
		for(int k = 0; k < 11; k++)check[k] = false;

		for(int k = 0; k < country_index; k++){
			if(i != k && adj_check[i][k] == true && shishimaru.colors[k] != -1){
				check[shishimaru.colors[k]] = true;
			}
		}

		Shishimaru next_shishimaru;
		for(int k = 0; k < country_index; k++){
			next_shishimaru.colors[k] = shishimaru.colors[k];
		}

		for(int k = 1; k <= 10; k++){
			if(check[k] == false){
				next_shishimaru.colors[i] = k;
				break;
			}
		}

		recursive(next_shishimaru,count+1);
	}
}

int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

double calc_slope(Line line){

	if(fabs(line.p1.y - line.p2.y) < EPS){
		return 0.0;
	}else if(fabs(line.p1.x - line.p2.x) < EPS){
		return NUM;
	}else{
		return (line.p1.y-line.p2.y)/(line.p1.x-line.p2.x);
	}
}

void solve(){

	Country country[N];
	country_index = 0;

	for(int i = 0; i < N; i++){
		country[i].color = -1;
	}

	char buf[21];

	int tmp_index;

	for(int loop = 0; loop < N; loop++){
		scanf("%s",buf);

		tmp_index = -1;
		for(int i = 0; i < country_index; i++){
			if(strCmp(country[i].name,buf)){
				tmp_index = i;
				break;
			}
		}
		if(tmp_index == -1){
			strcpy(country[country_index].name,buf);
			tmp_index = country_index;
			country_index++;
		}

		Region new_region;
		Line new_line;

		double x,y,pre_x = -1.0,pre_y = -1.0;

		while(true){
			scanf("%lf",&x);
			if(fabs(x + 1.0) < EPS){
				new_line.p1.x = pre_x;
				new_line.p1.y = pre_y;
				new_line.p2.x = new_region.Lines[0].p1.x;
				new_line.p2.y = new_region.Lines[0].p1.y;
				new_region.Lines.push_back(new_line);
				break;
			}
			scanf("%lf",&y);

			if(fabs(pre_x+1.0) > EPS){
				new_line.p1.x = pre_x;
				new_line.p1.y = pre_y;
				new_line.p2.x = x;
				new_line.p2.y = y;
				new_region.Lines.push_back(new_line);
			}

			pre_x = x;
			pre_y = y;
		}

		country[tmp_index].regions.push_back(new_region);
	}


	if(country_index == 1){
		printf("1\n");
		return;
	}

	for(int i = 0; i < country_index; i++){
		for(int k = 0; k < country_index; k++){
			adj_check[i][k] = false;
		}
	}

	bool adj_FLG;
	double tmp_slope;

	vector<Data> calc_V;

	for(int i = 0; i < country_index; i++){

		for(int k = 0; k < country_index; k++){
			if(i == k)continue;

			adj_FLG = false;

			for(int a = 0; a < country[i].regions.size(); a++){
				for(int b = 0; b < country[k].regions.size(); b++){
					for(int c = 0; c < country[i].regions[a].Lines.size(); c++){
						for(int d = 0; d < country[k].regions[b].Lines.size();d++){


							if(fabs((tmp_slope = calc_slope(country[i].regions[a].Lines[c])) - calc_slope(country[k].regions[b].Lines[d])) < EPS){

								calc_V.clear();

								if(fabs(tmp_slope) < EPS && country[i].regions[a].Lines[c].p1.y == country[k].regions[b].Lines[d].p1.y &&
										country[i].regions[a].Lines[c].p2.y == country[k].regions[b].Lines[d].p2.y){

									calc_V.push_back(Data(country[i].regions[a].Lines[c].p1.x,true));
									calc_V.push_back(Data(country[i].regions[a].Lines[c].p2.x,true));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p1.x,false));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p2.x,false));

									sort(calc_V.begin(),calc_V.end());

									if(calc_V[0].is_i != calc_V[1].is_i && fabs(calc_V[1].value - calc_V[2].value) > 0.1){
										adj_FLG = true;
										break;
									}
								}else if(fabs(tmp_slope-NUM) < EPS && country[i].regions[a].Lines[c].p1.x == country[k].regions[b].Lines[d].p1.x &&
										country[i].regions[a].Lines[c].p2.x == country[k].regions[b].Lines[d].p2.x){

									calc_V.push_back(Data(country[i].regions[a].Lines[c].p1.y,true));
									calc_V.push_back(Data(country[i].regions[a].Lines[c].p2.y,true));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p1.y,false));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p2.y,false));

									sort(calc_V.begin(),calc_V.end());

									if(calc_V[0].is_i != calc_V[1].is_i && fabs(calc_V[1].value - calc_V[2].value) > 0.1){
										adj_FLG = true;
										break;
									}
								}else if(fabs(tmp_slope-0.0) > EPS && fabs(tmp_slope-NUM) > EPS){

									if(func(country[i].regions[a].Lines[c].p1.x,country[i].regions[a].Lines[c].p1.y,
												country[i].regions[a].Lines[c].p2.x,country[i].regions[a].Lines[c].p2.y,
												country[k].regions[b].Lines[d].p1.x,country[k].regions[b].Lines[d].p1.y)*
										func(country[i].regions[a].Lines[c].p1.x,country[i].regions[a].Lines[c].p1.y,
												country[i].regions[a].Lines[c].p2.x,country[i].regions[a].Lines[c].p2.y,
												country[k].regions[b].Lines[d].p2.x,country[k].regions[b].Lines[d].p2.y) <= 0 &&
										func(country[k].regions[b].Lines[d].p1.x,country[k].regions[b].Lines[d].p1.y,
												country[k].regions[b].Lines[d].p2.x,country[k].regions[b].Lines[d].p2.y,
												country[i].regions[a].Lines[c].p1.x,country[i].regions[a].Lines[c].p1.y)*
										func(country[k].regions[b].Lines[d].p1.x,country[k].regions[b].Lines[d].p1.y,
												country[k].regions[b].Lines[d].p2.x,country[k].regions[b].Lines[d].p2.y,
												country[i].regions[a].Lines[c].p2.x,country[i].regions[a].Lines[c].p2.y) <= 0){

										calc_V.push_back(Data(country[i].regions[a].Lines[c].p1.x,true));
										calc_V.push_back(Data(country[i].regions[a].Lines[c].p2.x,true));
										calc_V.push_back(Data(country[k].regions[b].Lines[d].p1.x,false));
										calc_V.push_back(Data(country[k].regions[b].Lines[d].p2.x,false));

										sort(calc_V.begin(),calc_V.end());

										if(calc_V[0].is_i != calc_V[1].is_i && fabs(calc_V[1].value - calc_V[2].value) > 0.1){
											adj_FLG = true;
											break;
										}
									}
								}
							}
						}
						if(adj_FLG)break;
					}
					if(adj_FLG)break;
				}
				if(adj_FLG)break;
			}

			if(adj_FLG){
				adj_check[i][k] = true;
			}
		}
	}

	ans = BIG_NUM;

	for(int i = 0; i < country_index; i++){
		Shishimaru shishi;
		for(int k = 0; k < country_index; k++){
			shishi.colors[k] = -1;
		}
		shishi.colors[i] = 1;
		recursive(shishi,1);
	}

	printf("%d\n",ans);
}



int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		solve();
	}

	return 0;
}