#include <stdio.h>
#include <math.h>
#define REP(i, a, n) for(int i = (a); i < (n); i++)

int N, X[24], Y[24], R[24], C[24];
int r[24], m[24];
char dp[16777216];

int f(char n, int s) { return ((s & r[n]) & m[n]) == 0; }
char max(char a, char b) { return a > b ? a : b; }

char dfs(int s, char n) {
  if(n == N) return N;

  char ret = n;
  REP(i, 0, N) {
    int mi = (1 << i);
    if((~s & mi) || !f(i, s)) continue;
    REP(j, i + 1, N) {
      int mj = (1 << j);
      if(C[i] != C[j] || (~s & mj) || !f(j, s)) continue;
      int ns = ~(~s | mi | mj);
      if(dp[ns] >= 0) continue;
      ret = max(ret, dfs(ns, n + 2));
    }
  }

  return dp[s] = ret;
}

int main(void) {
  m[0] = 0;
  REP(i, 0, 23) m[i + 1] = m[i] | (1 << i);
  while(scanf("%d", &N), N) {
    REP(i, 0, N) scanf("%d %d %d %d", X + i, Y + i, R + i, C + i);
    REP(i, 0, pow(2, N)) dp[i] = -1;
    REP(i, 0, N) r[i] = 0;
    REP(i, 0, N) REP(j, 0, N) {
      if(pow(R[i] + R[j], 2) > pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2)) {
        r[i] = r[i] | (1 << j);
        r[j] = r[j] | (1 << i);
      }
    }
    printf("%d\n", dfs((1 << N) - 1, 0));
  }
  return 0;
}