#include<stdio.h>
struct A {
    int x;
    int y;
    int r;
    int c;
}a[30];
char dp[1<<25];
int n;
inline bool cover(int qq,int x) {
    int tmp,i;
    for(i=qq-1;i>=0;i--) {
        if(((x>>i)&1)==0) continue;
        tmp=(a[qq].x-a[i].x)*(a[qq].x-a[i].x)+(a[qq].y-a[i].y)*(a[qq].y-a[i].y);
        if((a[qq].r+a[i].r)*(a[qq].r+a[i].r)>tmp) break;
    }
    return i!=-1;
}
char maxnum(char x) {
    if(dp[x]!=-1) return dp[x];
    int i,j,k,tmp;
    char ans=0,y;
    for(i=0;i<n;i++) {
        if(((x>>i)&1)==0) continue;
        if(cover(i,x)) continue;
        for(j=i+1;j<n;j++) {
            if(((x>>j)&1)==0) continue;
            if(a[i].c!=a[j].c) continue;
            if(cover(j,x)) continue;
            y=x-(1<<i)-(1<<j);
            tmp=maxnum(y)+2;
            if(ans<tmp) ans=tmp;
        }
    }
    dp[x]=ans;
    return ans;
}
int main() {
    int i;
    while(scanf("%d",&n),n) {
        for(i=0;i<n;i++) {
            scanf("%d %d %d %d",&a[i].x,&a[i].y,&a[i].r,&a[i].c);
            dp[1<<i]=0;
        }
        for(i=0;i<(1<<n);i++)
            dp[i]=-1;
        dp[0]=0;
        printf("%d\n",maxnum((1<<n)-1));
    }
    return 0;
}