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

#define N 24
#define SQ(X) \
  ( (int)(X) * (int)(X) )
#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

static unsigned char x[ N ];
static unsigned char y[ N ];
static unsigned char r[ N ];
static unsigned char c[ N ];
static int           n;

static signed char k_operafan[ 1 << N ];

static signed char
dpFSA (
  const unsigned int rq
  )
{
  int i, j, k;

  if ( ~k_operafan[ rq ] ) ;
  else
  {
    k_operafan[ rq ] = 0;

    for ( i = 0; i < n; ++i )
    {
      if ( !( rq & ( 1 << i ) ) ) continue ;
      for ( j = i + 1; j < n; ++j )
      {
        if ( !( rq & ( 1 << j ) ) ) continue ;
        if ( c[ i ] != c[ j ] )     continue ;

        for ( k = 0; k < j; ++k )
        {
          if ( !( rq & ( 1 << k ) ) ) continue ;
          if ( SQ( x[ k ] - x[ j ] ) + SQ( y[ k ] - y[ j ] )
             < SQ( r[ k ] + r[ j ] ) ) break ;
          if ( k < i
            && SQ( x[ k ] - x[ i ] ) + SQ( y[ k ] - y[ i ] )
             < SQ( r[ k ] + r[ i ] ) ) break ;
        }
        if ( k == j )
        {
          const unsigned char res
            = dpFSA ( rq & ~( 1 << i ) & ~( 1 << j ) ) + 2;

          k_operafan[ rq ] = MAX( k_operafan[ rq ], res );
        }
      }
    }
  }

  return ( k_operafan[ rq ] );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      unsigned int tx, ty, tr, tc;

      scanf ( "%u%u%u%u", &tx, &ty, &tr, &tc );
      x[ i ] = tx; y[ i ] = ty; r[ i ] = tr; c[ i ] = tc;
    }

    memset ( k_operafan, -1, sizeof ( k_operafan ) );
    printf ( "%d\n", dpFSA ( ( 1 << n ) - 1 ) );
  }

  return ( 0 );
}