#include <stdio.h>
#include <stdlib.h>

#define N 300

struct C
{
  int i;
  int u;
  int a;
  int p;
};
#define C(X) \
  ( *( (struct C *)(X) ) )

int
compare (
  const void  * a,
  const void  * b
  )
{
  int res;

  res = C( b ).a - C( a ).a;
  if ( res ) return ( res );

  res = C( a ).p - C( b ).p;
  if ( res ) return ( res );

  return ( C( a ).i - C( b ).i );
}

int
main (
  )
{
  int i, c;

  for ( ; ; )
  {
    struct C d[ N ];
    int u[ 1001 ] = { 0 };
    int n;

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

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d%d%d%d", &d[ i ].i, &d[ i ].u, &d[ i ].a, &d[ i ].p );
    }
    qsort ( d, n, sizeof ( struct C ), compare );

    for ( c = 0; c < 26; ++c )
    {
      for ( i = 0; i < n; ++i )
      {
        if ( d[ i ].u < 0 ) continue ;

        if ( c < 10 )
        {
          if ( u[ d[ i ].u ] < 3 )
          {
            printf ( "%d\n", d[ i ].i );
            ++u[ d[ i ].u ];
            d[ i ].u = -1;
            break ;
          }
          continue ;
        }

        if ( c < 20 )
        {
          if ( u[ d[ i ].u ] < 2 )
          {
            printf ( "%d\n", d[ i ].i );
            ++u[ d[ i ].u ];
            d[ i ].u = -1;
            break ;
          }
        }

        if ( c < 26 )
        {
          if ( u[ d[ i ].u ] < 1 )
          {
            printf ( "%d\n", d[ i ].i );
            ++u[ d[ i ].u ];
            d[ i ].u = -1;
            break ;
          }
        }
      }
      if ( i >= n ) break ;
    }
  }

  return ( 0 );
}