#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[100];
ll d[100];

void addedge(int st, int ed, int co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

bool bo[100];
int cir[100][4];

int dfs() {
    vector<int> vec[4];
    int rem[4] = {0, 0, 0, 0};
    for (int i = 0; i < V; i++) {
        if (!bo[i]) {
            rem[cir[i][3] - 1]++;
        }
    }
    for (int i = 0; i < V; i++) {
        if (!bo[i]) {
            int len = G[i].size();
            bool ok = true;
            for (int j = 0; j < len; j++) {
                if (!bo[G[i][j].to]) {
                    ok = false;
                }
            }
            if (ok) {
                int c = cir[i][3];
                vec[c - 1].push_back(i);
            }
        }
    }
    int allnum = 0;
    bool all[4];
    vector<int> allv[4];
    fill(all, all + 4, false);
    for (int i = 0; i < 4; i++) {
        int len = vec[i].size();
        if (len == rem[i] && len % 2 == 0 && len > 0) {
            allnum += len;
            for (int j = 0; j < len; j++) {
                bo[vec[i][j]] = true;
                allv[i].push_back(vec[i][j]);
            }
            all[i] = true;
        }
    }
    // for (int i = 0; i < 4; i++) {
    //     int len = vec[i].size();
    //     for (int j = 0; j < len; j++) {
    //         cout << vec[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << "aaa " << allnum << endl;
    int ans = 0;
    for (int i = 0; i < 4; i++) {
        if (!all[i]) {
            int len2 = vec[i].size();
            for (int j = 0; j < len2; j++) {
                int p = vec[i][j];
                bo[p] = true;
                for (int k = j + 1; k < len2; k++) {
                    int q = vec[i][k];
                    bo[q] = true;
                    int num = dfs();
                    ans = max(ans, num + 2);
                    bo[q] = false;
                }
                bo[p] = false;
            }
        } else {
            int num = dfs();
            ans = max(ans, num);
        }
    }
    for (int i = 0; i < 4; i++) {
        if (all[i]) {
            int len = allv[i].size();
            for (int j = 0; j < len; j++) {
                bo[allv[i][j]] = false;
            }
        }
    }
    return ans + allnum;
}

int main() {
    while (1) {
        int n;
        cin >> n;
        V = n;
        if (n == 0) {
            break;
        }
        fill(bo, bo + V, false);
        for (int i = 0; i < V; i++) {
            G[i].clear();
        }
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < 4; j++) {
                cin >> cir[i][j];
            }
        }
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < i; j++) {
                double d = sqrt((cir[i][0] - cir[j][0]) *
                                (cir[i][0] - cir[j][0])
                                + (cir[i][1] - cir[j][1]) *
                                (cir[i][1] - cir[j][1]));
                if (d + eps < cir[i][2] + cir[j][2]) {
                    addedge(i, j, 0);
                }
            }
        }
        ll ans = dfs();
        cout << ans << endl;
    }
}



Measured memory_bytes: 3112