import std.stdio, std.string, std.conv, std.algorithm, std.array;

struct Team {
  int l;
  int u;
  int a;
  int p;

  this( int l, int u, int a, int p ) {
	this.l = l;
	this.u = u;
	this.a = a;
	this.p = p;
  }

  int opCmp( Team t ) {
	if ( a != t.a ) return t.a - a;
	else if ( p != t.p ) return p - t.p;
	else return l - t.l;
  }
}

void main() {
  while ( true ) {
	int n = to!int( strip( readln ) );
	if ( n == 0 ) break;
	Team[] ts = new Team[]( n );
	int[ int ] table;
	foreach ( i; 0 .. n ) {
	  auto tokens = map!( to!int )( split( strip( readln ) ) );
	  ts[ i ] = Team( tokens[ 0 ], tokens[ 1 ], tokens[ 2 ], tokens[ 3 ] );
	  table[ ts[ i ].u ] = 0;
	}
	sort( ts );
	int count = 0;

	foreach ( t; ts ) {
	  if ( count < 10 ) {
		if ( table[ t.u ] < 3 ) {
		  writeln( t.l );
		  table[ t.u ] += 1;
		}
	  } else if ( count < 20 ) {
		if ( table[ t.u ] < 2 ) {
		  writeln( t.l );
		  table[ t.u ] += 1;
		}
	  } else if ( count < 26 ) {
		if ( table[ t.u ] < 1 ) {
		  writeln( t.l );
		  table[ t.u ] += 1;
		}
	  }
	}
  }  
}