// Arup Guha
// 6/30/2013
// Solution to 2012 MCPC Problem F: LRU Caching

import java.util.*;

public class f {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int loop = 1;

		// Go through each case.
		while (n != 0) {

			System.out.println("Simulation "+loop);
			String s = stdin.next();

			// Set up cache.
			cacheitem[] cache = new cacheitem[n];
			for (int i=0; i<n; i++)
				cache[i] = null;

			// Simulate each item.
			for (int i=0; i<s.length(); i++) {

				// Print step.
				if (s.charAt(i) == '!') {
					ArrayList<cacheitem> temp = new ArrayList<cacheitem>();
					for (int k = 0; k<n && cache[k] !=null; k++)
						temp.add(cache[k]);
					Collections.sort(temp);
					print(temp);
				}
				else {

					// Look for item already.
					boolean done = false;
					int j = 0;
					int oldestIndex = 0;
					for (j=0; j<cache.length && cache[j] != null; j++) {
						
						// We found the item, update its last used.
						if (s.charAt(i) == cache[j].item) {
							cache[j].lastUsed = i;
							done = true;
							break;
						}

						// Update the oldestIndex, which is the one that needs to be replaced next.
						if (cache[j].lastUsed < cache[oldestIndex].lastUsed) {
							oldestIndex = j;
						}
					}

					// New spot found for insertion.
					if (j < cache.length) {
						cache[j] = new cacheitem(s.charAt(i), i);
					}

					// Must replace
					else {
						cache[oldestIndex] = new cacheitem(s.charAt(i), i);
					}

				}
			}

			loop++;
			n = stdin.nextInt();
		}

	}

	public static void print(ArrayList<cacheitem> array) {

		for (int i=0; i<array.size(); i++)
			System.out.print(array.get(i).item);
		System.out.println();
	}
}

// Here is how we want to sort, before we print.
class cacheitem implements Comparable<cacheitem> {

	public char item;
	public int lastUsed;

	public cacheitem(char c, int i) {
		item = c;
		lastUsed = i;
	}

	public int compareTo(cacheitem other) {
		return this.lastUsed - other.lastUsed;
	}
}