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

#define N_BIT (1<<24)
#define N 24

#define isDeleted(i,s) (s & (1<<i)) ? 1:0
#define removeDisc(i,j,s) (s | (1<<i) | (1<<j))
#define max(x,y) (x>y) ? x:y

int x[N],y[N],r[N],c[N],st[N];

int n;				//Disc????????°
char dp[N_BIT];		//????????¶????????????????????????????????°????????§??????????´?????????????(?????¢?´¢?????´??????-1)


int isRemovable(int i,int j,int s){			//??¶???s????????????i?????????Disc?????????????????§?????????
	int k;
	for(k=i-1;k>=0;k--){
		if(st[k]){		//k???????????¢??????????????????????£???°???
			continue;
		}
		if((r[i]+r[k])*(r[i]+r[k]) > (x[i]-x[k])*(x[i]-x[k])+(y[i]-y[k])*(y[i]-y[k])){		//?????¢?????¢???????????????
			return 0;
		}
	}
	for(k=j-1;k>=0;k--){
		if(st[k]){		//k???????????¢??????????????????????£???°???
			continue;
		}
		if((r[j]+r[k])*(r[j]+r[k]) > (x[j]-x[k])*(x[j]-x[k])+(y[j]-y[k])*(y[j]-y[k])){		//?????¢?????¢???????????????
			return 0;
		}
	}
	return 1;
}

//??±???????????¢?´¢(?????¢????????°)
int dfsearch(int s){		//s?????¶????????????
	if(dp[s] != -1){		//??¶???s?????¢?????¢?´¢????????§????????°?¨?????????????
		return dp[s];
	}
	int i,j,value=0;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			//??¶???s????????????i,j?????????Disc???????????????Disc???????????£????????????,??????????????§??????,?????????i,j??????????????????????????´???
			if(isRemovable(i,j,s) && !st[i] && !st[j] && c[i] == c[j]){
				st[i] = st[j] = 1;
				value = max(value,dfsearch(removeDisc(i,j,s))+2);		//i,j???2???????????? + i,j????????????????????\?????§????????§????????¢?´¢??§?±???????
				st[i] = st[j] = 0;
			}
		}
	}
	return dp[s] = value;
}

int main(void){
	int i;
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d %d %d %d",&x[i],&y[i],&r[i],&c[i]);
			st[i] = 0;
		}
		memset(dp,-1,sizeof(dp));
		printf("%d\n",dfsearch(0));		//s=0:??¨??????Disc????????¨????????¶???
	}
	return 0;
}