// 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 s, del, m; } Q;
Q q[100000]; int top;
typedef struct { int x, y, r, c; } T;
T d[25]; int n;
typedef struct { int n, id[25]; } S;
S up[25];			// ?????????????????????????????°??¨??????
char visited[16777216];

int main()
{
	int i, j, k, a, s, del, m, ans;

	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(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) {
				up[j].id[up[j].n++] = i;
			}
		}

		ans = 0;
		memset(visited, 0, sizeof(visited));
		q[0].s = 0, q[0].del = 0, q[0].m = n, top = 1;
		while (top) {
			s = q[--top].s, del = q[top].del, m = q[top].m;

			if (m == 1 || visited[s]) continue;
			visited[s] = 1;
			for (i = 0; i < n; i++) {
				if (s & (1<<i)) continue;
				for (k = 0; k < up[i].n; k++) {
					a = up[i].id[k];
					if (!(s & (1<<a))) goto next;
				}

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

					if (del+2 > ans) ans = del+2;
					q[top].s = s|(1<<i) | (1<<j), q[top].del = del+2, q[top++].m = m-2;

					next2:;
				}
				next:;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}