/*
  lru.java
  LRU Caching, MCPC 2012 Problem F
  Java solution by Gabriel Foust
*/

import java.io.*;
import java.util.*;

class lru
{
    public static void mainString[] args throws FileNotFoundException
    {
        Scanner scanner= new Scannernew File"lru.in" ) );
        ArrayList<Character> cache;
        int cache_size;
        String commandString;
        int count= 0;
        while ((cache_size= scanner.nextInt()) 0)
        {
            System.out.println"Simulation " + ++count );
            cache= new ArrayList<Character>();
            commandString= scanner.next();
            for (int i= 0; i < commandString.length(); ++i)
            {
                char command= commandString.charAt);
                if (command == '!')
                {
                    if (cache.size() == 0)
                        System.out.println"empty" );
                    else
                    {
                        for (Character c : cache)
                            System.out.print);
                        System.out.println();
                    }
                }
                else
                {
                    cache.remove( (Character)command );
                    if (cache.size() == cache_size)
                        cache.remove);
                    cache.addcommand );
                }
            }
        }
    }
}