// AOJ 1175: And Then. How Many Are There?
// 2017.12.21 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

typedef struct { int x, y, r, c; } T;
T d[25]; int n;
char rel[25][25];	// rel[i][j]???1??¨????????????i???j??????????????£??????j?????????????????¶???
typedef struct { int n, id[25]; } S;
S up[25];			// ?????????????????????????????°??¨??????
char none[16];
char visited[16777216];
int ans;

void dfs(int s, int del, int m)
{
	int i, j, k, a;

	if (m == 1) return;
	if (visited[s]) return;
	visited[s] = 1;
	for (i = 0; i < n; i++) {
		if (none[i]) continue;
		for (k = 0; k < up[i].n; k++) {
			a = up[i].id[k];
			if (!none[a]) break;
		}
		if (k != up[i].n) continue;

		for (j = i+1; j < n; j++) {
			if (none[j]) continue;
			if (d[j].c != d[i].c) continue;
			for (k = 0; k < up[j].n; k++) {
				a = up[j].id[k];
				if (!none[a]) break;
			}
			if (k != up[j].n) continue;

			if (del+2 > ans) ans = del+2;
			none[i] = none[j] = 1;
			dfs(s|(1<<i) | (1<<j), del+2, m-2);
			none[i] = none[j] = 0;
		}
	}
}

int main()
{
	int i, j;

	while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d%d%d%d", &d[i].x, &d[i].y, &d[i].r, &d[i].c);
		memset(rel, 0, sizeof(rel));
		memset(up, 0, sizeof(up));
		for (i = 0; i < n; i++) for (j = i+1; j < n; j++) {
			if (hypot(d[i].x-d[j].x, d[i].y-d[j].y) < d[i].r+d[j].r) {
				rel[i][j] = 1;
				up[j].id[up[j].n++] = i;
			}
		}

		ans = 0;
		memset(none, 0, sizeof(none));
		memset(visited, 0, sizeof(visited));
		dfs(0, 0, n);
		printf("%d\n", ans);
	}
	return 0;
}