import java.io.*;
import java.lang.*;

public class exchange{

  public static void main(String[] args){
     readIn();

  }

  public static void readIn(){
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    boolean zmena=true;
    String firmy[]= new String[10];	
    char[] pole;
    int buy[] = new int[3];
    int sell[] = new int[3];

    char[] prvni= new char[20];
    char[] druhy= new char[20];
    char[] treti= new char[20];  
    String x;
    String y;	
    int c=0;
    int d=0;
    int kterePole=0;
    int pocet=0;

    int dalsiPocitadlo=0;

    try{
	while(true){
	x=br.readLine();
	if(x.charAt(0)=='0')break;	
	pole=new char[x.length()];
	
	for(int i=0;i<pole.length;i++){
	     if(pole[i]!=' ' && kterePole==0){
		 prvni[i]=pole[i];
	         c=i;
	     }
	     if(pole[i]!=' ' && kterePole==1){
		 druhy[i-c]=pole[i];
	         d=i;
	      }
	     if(pole[i]!=' ' && kterePole==2){
		 treti[i-d]=pole[i];
	     }	
	     if(pole[i]==' ') kterePole++;
	}
	if(treti==null){
          y=prvni.toString();
	  pocet=Integer.parseInt(y);
	  while(druhy!=null){
             int cout=0;
	     System.out.print(druhy[cout]);
             cout++;
	  }
          System.out.println();
	}
        if(zmena==true) {
	   firmy=new String[pocet];
           buy= new int[pocet];
           sell=new int[pocet];
           zmena=false;
        }
	
	if(dalsiPocitadlo!=pocet){
          firmy[dalsiPocitadlo]=prvni.toString();
          if(druhy[0]=='b'){
	    buy[dalsiPocitadlo]=Integer.parseInt(treti.toString());   
	  }
	  if(druhy[0]=='s'){
	    sell[dalsiPocitadlo]=Integer.parseInt(treti.toString());   
	  }
	}
	else{
	   for(int i=0;i<pocet;i++){
	     System.out.print(firmy[i]+": ");
	     if(buy[i]==0){
		boolean uzZas=false; 	         
		for(int k=0;k<pocet;k++){
                     if(sell[i]<=buy[k] && buy[k]!=0){
		         uzZas=true;
			 System.out.print(firmy[k]+" ");
		     }		
		 }
		if(uzZas==false) System.out.print("NO-ONE");
		System.out.println();
	     }
	     if(sell[i]==0){
		boolean uzZas=false;
 	         for(int k=0;k<pocet;k++){
                     if(buy[i]>=sell[k] && sell[k]!=0){
		         uzZas=true;
			 System.out.print(firmy[k]+" ");
		     }		
		 }
		if(uzZas==false) System.out.print("NO-ONE");
		System.out.println();
	     }
	   }	
	}
	dalsiPocitadlo++;
	
	}	
    }catch(IOException e){};
  }



}
