#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

#define pb push_back

int anss = 0;

int calculate(int x,int y,int r,int xx,int yy,int rr){
    int d = (x-xx)*(x-xx)+(y-yy)*(y-yy);
    if(d >= (r+rr)*(r+rr)) return 0;
    else return 1;
}

void play(int n,int top[],int col[],vector <int> colors[]){
    //cout << endl << endl;
    vector <int> pos[6];
    int ans=0;
    for(int i = 0 ; i < n ; i++){
        //cout << "t " << i << " " << top[i] << endl;
        if(top[i] == 0){
            pos[col[i]].pb(i);
        }
        if(top[i] == -1) ans++;
    }

    anss = max(ans,anss);
    /*
    for(int i = 1 ; i < 4 ; i++){
        //cout << i << " : ";
        for(int j = 0 ; j < pos[i].size() ; j++) cout << pos[i][j] << " ";
        cout << endl;
    }
    */
    for(int i = 1 ; i <= 4 ; i++){
        if(pos[i].size() == 6){
            //cout << "x" << endl;
            int topp[30];

            for(int j = 0 ; j < n ; j++) topp[j] = top[j];

            for(int j = 0 ; j < n ; j++){
                //cout << "shift " << pos[i][0] << " " << pos[i][1] << endl;
                //cout << "shiff " << j << " " << topp[j] << " " << (topp[j] & (1<<pos[i][0])) << endl;

                if( (topp[j] & (1<<pos[i][0])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][0];
                if( (topp[j] & (1<<pos[i][1])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][1];
                if( (topp[j] & (1<<pos[i][2])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][2];
                if( (topp[j] & (1<<pos[i][3])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][3];
                if( (topp[j] & (1<<pos[i][4])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][4];
                if( (topp[j] & (1<<pos[i][5])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][5];
            }

            topp[pos[i][0] ] = -1;
            topp[pos[i][1] ] = -1;
            topp[pos[i][2] ] = -1;
            topp[pos[i][3] ] = -1;
            topp[pos[i][4] ] = -1;
            topp[pos[i][5] ] = -1;
            play(n,topp,col,colors);
        }

        else if(pos[i].size() == 4 && colors[i].size() == 4){
            //cout << "x" << endl;
            int topp[30];

            for(int j = 0 ; j < n ; j++) topp[j] = top[j];

            for(int j = 0 ; j < n ; j++){
                //cout << "shift " << pos[i][0] << " " << pos[i][1] << endl;
                //cout << "shiff " << j << " " << topp[j] << " " << (topp[j] & (1<<pos[i][0])) << endl;

                if( (topp[j] & (1<<pos[i][0])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][0];
                if( (topp[j] & (1<<pos[i][1])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][1];
                if( (topp[j] & (1<<pos[i][2])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][2];
                if( (topp[j] & (1<<pos[i][3])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][3];
            }

            topp[pos[i][0] ] = -1;
            topp[pos[i][1] ] = -1;
            topp[pos[i][2] ] = -1;
            topp[pos[i][3] ] = -1;
            play(n,topp,col,colors);
        }
        else if(pos[i].size() >= 2){
            do{
                int topp[30];

                for(int j = 0 ; j < n ; j++) topp[j] = top[j];

                for(int j = 0 ; j < n ; j++){
                    //cout << "shift " << pos[i][0] << " " << pos[i][1] << endl;
                    //cout << "shiff " << j << " " << topp[j] << " " << (topp[j] & (1<<pos[i][0])) << endl;

                    if( (topp[j] & (1<<pos[i][0])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][0];
                    if( (topp[j] & (1<<pos[i][1])) > 0 && topp[j] > 0 ) topp[j] -= 1<<pos[i][1];
                }

                topp[pos[i][0] ] = -1;
                topp[pos[i][1] ] = -1;
                play(n,topp,col,colors);
            }while(next_permutation( pos[i].begin(),pos[i].end() ) );
        }
    }

    //cout << "end" << endl;
}
main(){
    //freopen("D.txt","r",stdin);
    int n;

    while(cin >> n,n>0){
        int top[30]={0};
        int xx[30];
        int yy[30];
        int rad[30];
        int col[30];
        vector <int> colors[6];

        for(int i = 0 ; i < n ; i++){
            cin >> xx[n-i-1] >> yy[n-1-i] >> rad[n-1-i] >> col[n-1-i];

            colors[col[n-1-i]].pb(n-1-i);
        }

        for(int i = 0; i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                if(calculate(xx[j],yy[j],rad[j],xx[i],yy[i],rad[i])==1){
                    top[j]+=1<<i;
                }
            }
        }

        anss = 0;
        play(n,top,col,colors);

        cout << anss << endl;
    }
    return 0;
}

Measured memory_bytes: 1220