Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7FFFFFFF

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		chairs := make([]string, n)
		for i := range chairs {
			chairs[i] = "#"
		}
		sit := func(who string) {
			if who == "A" {
				chairs[getStringIndex(chairs, "#")] = "A" // A国の人は左から見て行って空いている席を見つけ次第座る
				// log.Println(chairs)
			} else if who == "B" {
				f := true
				for i := n-1; i > -1; i-- {
					// B国の人はA国人の隣以外で、右端から空いている椅子に座る
					if chairs[i] == "#" && (i == 0 || chairs[i-1] != "A") && (i == n-1 || chairs[i+1] != "A") {
								chairs[i] = "B"
								f = false
								break
					}
				}
				// A国人の隣しか空いていない場合、我慢して左端から空いている椅子に座る
				if f {
					chairs[getStringIndex(chairs, "#")] = "B"
				}
				// log.Println(chairs)
			} else if who == "C" { // C国人は人の隣に座りたい
				for i := 0; i < n; i++ {
					if chairs[i] != "#" {
						if i + 1 <= n-1 && chairs[i+1] == "#" {
							chairs[i+1] = "C"
							break
						} else if i - 1 >= 0 && chairs[i-1] == "#" {
							chairs[i-1] = "C"
							break
						}
					}
				}
				// log.Println(chairs)
			} else { // who == "D"
				// D国の人は人から離れて座りたい
				// どうしても誰かの隣に座らなければならない場合、その中で一番左側にある椅子に座る
				scores := make([]int, n)
				for i := range scores {
					scores[i] = INF
				}
				for i, v := range chairs {
					if v == "#" {
						scores[i]++
					}
				}
				for i := n-1; i > -1; i-- {
					tmp := 0
					if chairs[i] == "#" {
						tmp++
					} else {
						tmp = 0
					}
					scores[i] = min(scores[i], tmp)
				}
				chairs[getIntIndex(scores, getMax(scores))] = "D"
				// log.Println(chairs)
			}
		}
		scanner.Scan()
		if first := scanner.Text(); first == "A" || first == "D" {
			chairs[0] = first
		} else if first == "B" {
			chairs[len(chairs)-1] = "B"
		} else {
			chairs[n/2] = "C"
		}
		// log.Println(chairs)
		for i := 0; i < m-1; i++ {
			scanner.Scan()
			sit(scanner.Text())
		}
		fmt.Println(strings.Join(chairs, ""))
	}
}

func getStringIndex(chairs []string, who string) int {
	for i, v := range chairs {
		if v == who {
			return i
		}
	}
	return -1
}

func getIntIndex(scores []int, target int) int {
	for i, v := range scores {
		if v == target {
			return i
		}
	}
	return -1
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func getMax(scores []int) int {
	tmp := -1
	for _, v := range scores {
		if tmp < v {
			tmp = v
		}
	}
	return tmp
}

C++: #include <bits/stdc++.h>
using namespace std;
// 12:46

string chair;


int goA(char c){
	for(int i = 0 ; i < chair.size() ; i++)
		if( chair[i] == '#'){
			chair[i] = c;
			return 1;
		}
	return 0;
}
int goB(char c){
	for(int i = chair.size() -1  ; i >= 0 ; i--)
		if( chair[i] == '#' && (!i||chair[i-1]!='A') && (i+1==chair.size()||chair[i+1]!='A') ){
			chair[i] = c;
			return 1;
		}
	return goA(c);
}
int goC(char c){
	if( count(chair.begin(),chair.end(),'#') == chair.size() ){
		if( chair.size() % 2 ) chair[(1+chair.size())/2-1] = c;
		else chair[chair.size()/2] = c;
		return 1;
	}
	for(int i = 0 ; i < chair.size() ; i++)
		if( chair[i] != '#'){
			for(int j = 1 ; j >= -1 ; j--){
				if( i+j >= 0 && i+j < chair.size() && chair[i+j] == '#' ){
					chair[i+j] = c;
					return 1;
				}
			}
		}

	return 0;
}
int goD(char c){
	int pos;
	int dst = -2e9;
	for(int i = 0 ; i < chair.size() ; i++){
		if( chair[i] == '#' ){
			int dist = 1e9;
			for(int j = 0 ; j < chair.size() ; j++)
				if( chair[j] != '#') dist = min(dist,abs(i-j));

			if( dst < dist){
				dst = dist;
				pos = i;
			}
		}
	}
	chair[pos] = c;
	return 1;
}


int main(){
	int n,m;
	while( cin >> n >> m && n ){
		chair = string(n,'#');
		for(int i = 0 ; i < m ; i++){
			char c; cin >> c;
			if( c == 'A' ) goA(c);
			if( c == 'B' ) goB(c);
			if( c == 'C' ) goC(c);
			if( c == 'D' ) goD(c);
		}
		cout << chair << endl;
	}
}

C++: #include <iostream>
using namespace std;
int m,n,j,k,f,g;
char c[101];
void acta() {
	for (j=0;j<m;j++) if (c[j]=='#') { c[j]='A'; break;}
}

void actb() {
	f=m-1;
	for (j=m-1;j>=0;j--) {
		if (c[j]!='#') continue;
		f=j;
		if (j==m-1) {if (c[m-2]!='A') break; else continue;} 
		if (j==0) {if (c[1]!='A') break; else continue;}
		if (c[j-1]!='A' && c[j+1]!='A') break;
	}
	c[f]='B';
}

void actc() {
	if (g==0) {c[(m-1)/2]='C'; return;}
	for (j=0;j<m;j++) {
	 if (c[j]!='#') {
		 if (j<m-1) if (c[j+1]=='#') { c[j+1]='C'; break;}
		 if (j>0) if (c[j-1]=='#') { c[j-1]='C'; break;}
	 }   	
	}
}
void actd() {
	int l=0,sx=0,x=0;
	f=0;
	if (g==0) {c[0]='D';return;}
	for (j=0;j<m;j++) {
		if (c[j]!='#') {
			if (f==0) { x=0; l=j;} else { if ((j-sx)/2>l) { l=(j-sx)/2; x=sx+l;}}
			sx=j; f=1;
		} else if (j==m-1) if (j-sx>l) x=j;
	}
	c[x]='D';
}
int main() {
	int i;
	char a;
	while(cin >> m >> n) {
		if (m+n==0) break;
		for (i=0;i<m;i++) c[i]='#'; c[i]='\0'; g=0;
		for (i=0;i<n;i++) {
			cin >> a;
			switch(a) {
				case 'A': acta(); break;
				case 'B': actb(); break;
				case 'C': actc(); break;
				case 'D': actd(); break;
			}
			g=1;
		}
		cout << c << endl;
	}	 
			  			
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, M;
char chairs[100];

int main(){
    while(std::cin >> N >> M, N){
        REP(i, N){chairs[i] = '#';}

        REP(i, M){
            char c;
            std::cin >> c;

            if(c == 'A'){
                REP(j, N){
                    if(chairs[j] == '#'){chairs[j] = 'A'; break;}
                }
            }else if(c == 'B'){
                bool can = false;
                for(int j=N-1;j>=0;j--){
                    if(chairs[j] != '#'){continue;}
                    if(j-1 >= 0 && chairs[j-1] == 'A'){continue;}
                    if(j+1 < N && chairs[j+1] == 'A'){continue;}
                    chairs[j] = 'B';
                    can = true;
                    break;
                }
                if(can){continue;}
                REP(j, N){
                    if(chairs[j] == '#'){chairs[j] = 'B'; break;}
                }
            }else if(c == 'C'){
                if(i == 0){chairs[N/2] = 'C'; continue;}

                REP(j, N){
                    if(chairs[j] == '#'){continue;}
                    if(j+1 < N && chairs[j+1] == '#'){chairs[j+1] = 'C'; break;}
                    if(j-1 >= 0 && chairs[j-1] == '#'){chairs[j-1] = 'C'; break;}
                }
            }else if(c == 'D'){
                int pos = -1, max_l = 0;
                REP(j, N){
                    if(chairs[j] != '#'){continue;}

                    int l1 = INF, l2 = INF;
                    for(int k=j-1;k>=0;k--){
                        if(chairs[k] != '#'){l1 = j-k; break;}
                    }
                    for(int k=j+1;k<N;k++){
                        if(chairs[k] != '#'){l2 = k-j; break;}
                    }

                    if(std::min(l1, l2) > max_l){pos = j; max_l = std::min(l1, l2);}
                }

                chairs[pos] = 'D';
            }
        }

        REP(i, N){
            putchar(chairs[i]);
        }
        puts("");
    }
}