#include<stdio.h>
#include<math.h>
#include<string.h>
const double EPS = 0.000001;
int N,X[50],Y[50],R[50],C[50],i,j,f[50];

int isOver(int a,int b)
{
	double x=sqrt((double)(X[a]-X[b])*(X[a]-X[b])+(Y[a]-Y[b])*(Y[a]-Y[b])),y=R[a]+R[b];
	if(y>x)return 1;
	return 0;
}

int ch(int n)
{
	int i;
	for(i=0;i<n;i++)
		if(!f[i]&&isOver(n,i))
			return 0;
	return 1;
}

int dfs(int n)
{
	int i,r=0,t;
	if(n==N)return 0;
	if(!f[n]&&ch(n))
	{
		for(i=0;i<N;i++)
			if(i!=n&&C[i]==C[n]&&!f[i]&&ch(i))
			{
				f[n]=f[i]=1;
				t=dfs(n+1)+2;
				r=r<t?t:r;
			}
	}
	t=dfs(n+1);
	r=r<t?t:r;
	return r;
}


int main()
{
	for(;scanf("%d",&N),N;)
	{
		memset(f,0,sizeof(f));
		for(i=0;i<N;i++)
			scanf("%d%d%d%d",&X[i],&Y[i],&R[i],&C[i]);
		printf("%d\n",dfs(0));
	}
	return 0;
}