// 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[10000]; int top;
typedef struct { int x, y, r; } T;
T d[25];
int col[4][6], clen[4]; char f[5];
int up[25][25], ulen[25];		// ?????????????????????????????°??¨??????
char visited[16777216];

int main()
{
	int n, i, j, k, a, c, cmax, l, p, r, s, del, m, ans;

	while (scanf("%d", &n) && n > 0) {
		memset(clen, 0, sizeof(clen)), memset(f, -1, sizeof(f)), cmax = 0;
		for (i = 0; i < n; i++) {
			scanf("%d%d%d%d", &d[i].x, &d[i].y, &d[i].r, &c);
			if  (f[c] >= 0)          c = f[c];
			else f[c] = cmax++, c = cmax-1;

			col[c][clen[c]++] = i;
		}

		memset(ulen, 0, sizeof(ulen));
		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][ulen[j]++] = i;
		}

		ans = 0;
		memset(visited, 0, 1 << n);
		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 (c = 0; c < cmax; c++)if ((l = clen[c]) >= 2) for (p = 0; p < l; p++) {
				i = col[c][p];
				if (s & (1<<i)) continue;
				for (k = 0; k < ulen[i]; k++) {
					a = up[i][k];
					if (!(s & (1<<a))) goto next;
				}

				for (r = p+1; r < l; r++) {
					j = col[c][r];
					if (s & (1<<j)) continue;
					for (k = 0; ; k++) {
						if (k == ulen[j]) {
							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;
							break;
						}
						a = up[j][k];
						if (!(s & (1<<a))) break;
					}
				}
				next:;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}