import java.lang.*; //or not
import java.io.*;

class Record{
    public String dept;
    public String ID;
    public String name;
}

public class OOPLotteryV2{
    public static Record getTokens(String str){        
        String[] tokens = str.split(",");
	Record r = new Record();
	r.dept = tokens[0];
	r.ID = tokens[1];
	r.name = tokens[2];
	return r;
    }

    public static Record[] combineList(Record[] orig, Record r){
	Record[] tmp = new Record[orig.length + 1];
	System.arraycopy(orig, 0, tmp, 0, orig.length);
	tmp[orig.length] = r;
	return tmp;
    }

    public static Record[] getNameList(String fileName){
	Record[] NameList = new Record[0];

	try{
	    BufferedReader NameListBuffer = 
		new BufferedReader(new FileReader(fileName));
	    
	    try{
		String line = null;

		while (( line = NameListBuffer.readLine()) != null){
		    Record r = getTokens(line);
		    NameList = combineList(NameList, r);
		}
	    }
	    finally {
		NameListBuffer.close();
	    }
	}
	catch (IOException ex){
	    System.err.println("Cannot open file " + fileName);
	    ex.printStackTrace();
	}
	return NameList;
    }

    public static int[] genRandomIndex(int len){
	int[] index = new int[len];
	for(int i=0;i<index.length;i++)
	    index[i] = i;

	java.util.Random rnd = new java.util.Random();
	for(int i=index.length-1;i>=0;i--){
	    int j = rnd.nextInt(i+1);
	    int tmp = index[j];
	    index[j] = index[i];
	    index[i] = tmp;
	}
	return index;
    }

    public static void main(String[] argv){
	Record[] NameList = getNameList(argv[0]);

	int[] index = genRandomIndex(NameList.length);
	
	int count = 0;
	while(true){
	    String action = System.console().readLine();
	    if (action.length() > 0 && action.charAt(0) == 'q')
		break;
	    else{
		System.out.println(NameList[index[count]].dept + 
				   "," + 
				   NameList[index[count]].name
				   );
		count++;
		if (count == index.length){
		    index = genRandomIndex(NameList.length);
		    count = 0;
		}
	    }
	}
    }
}

