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 <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector<char> v(n+2);
        for (int _ = 0; _ < m; ++_) {
            char c;
            cin >> c;
            if(c == 'A'){
                for (int j = 1; j <= n; ++j) {
                    if(!v[j]){
                        v[j] = c;
                        break;
                    }
                }
            }else if(c == 'B'){
                int ok = 0;
                for (int j = n; j >= 1; --j) {
                    if(!v[j] && v[j-1] != 'A' && v[j+1] != 'A'){
                        v[j] = c;
                        ok = 1;
                        break;
                    }
                }
                if(!ok){
                    for (int j = 1; j <= n; ++j) {
                        if(!v[j]){
                            v[j] = c;
                            break;
                        }
                    }
                }
            }else if(c == 'C'){
                int ok = 0;
                for (int j = 1; j <= n; ++j) {
                    if(!v[j]) continue;;
                    if(j != n && !v[j+1]){
                        v[j+1] = c;
                        ok = 1;
                        break;
                    }
                    if(j != 1 && !v[j-1]){
                        v[j-1] = c;
                        ok = 1;
                        break;
                    }
                }
                if(!ok){
                    v[(n+2)/2] = c;
                }
            }else if(c == 'D'){
                int cur = 1, dist = 0;
                for (int j = 1; j <= n; ++j) {
                    if(v[j]) continue;
                    int d = INF<int>;
                    for (int k = 1; k <= n; ++k) {
                        if(v[k]){
                            d = min(d, abs(j-k));
                        }
                    }
                    if(d > dist){
                        dist = d;
                        cur = j;
                    }
                }
                v[cur] = c;
            }
        }
        for (int i = 1; i <= n; ++i) {
            if(v[i]) cout << v[i];
            else cout << "#";
        }
        puts("");
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int isu[100];
int m;

void A(void){
	for(int i=0;i<m;i++){
		if(isu[i]==0){
			isu[i]=1;
			return;
		}
	}
}
void B(void){
	if(isu[m-1]==0 && isu[m-2]!=1){
		isu[m-1]=2;
		return;
	}
	for(int i=m-2;i>=1;i--){
		if(isu[i]==0 && isu[i+1]!=1 && isu[i-1]!=1){
			isu[i]=2;
			return;
		}
	}
	if(isu[0]==0&&isu[1]!=1){
		isu[0]=2;
		return;
	}
	
	for(int i=0;i<m;i++){
		if(isu[i]==0){
			isu[i]=2;
			return;
		}
	}
}
void C(void){
	int cont=0;
	for(int i=0;i<m;i++){
		cont+=isu[i];
	}
	if(cont==0){
		isu[m/2]=3;
		return;
	}
	
	if(isu[0]==0){
		for(int i=0;i<m;i++){
			if(isu[i]==0&&isu[i+1]!=0){
				isu[i]=3;
				return;
			}
		}
	}else{
		for(int i=0;i<m;i++){
			if(isu[i]==0){
				isu[i]=3;
				return;
			}
		}
	}
}
void D(void){
	int cent=0;
	for(int i=0;i<m;i++){
		cent+=isu[i];
	}
	if(cent==0){
		isu[0]=4;
		return;
	}
	
	int che[100];
	
	int cont=120;
	for(int i=0;i<m;i++){
		cont++;
		if(isu[i]!=0){
			cont=0;
		}
		che[i]=cont;
	}
	cont=120;
	for(int i=m-1;i>=0;i--){
		cont++;
		if(isu[i]!=0){
			cont=0;
		}
		che[i]=min(cont,che[i]);
	}
	int max=-1;
	int ele=0;
	for(int i=0;i<m;i++){
		if(che[i]>max){
			max=che[i];
			ele=i;
		}
	}
	isu[ele]=4;
	return;
}


int main(void){
	
	while(1){
		for(int i=0;i<100;i++){
			isu[i]=0;
		}
		
		int n;
		scanf("%d%d",&m,&n);
		
		if(n==0 && m==0){
			break;
		}
		
		for(int i=0;i<n;i++){
			char ch[10];
			scanf("%s",ch);
			
			switch(ch[0]){
				case 'A':A();break;
				case 'B':B();break;
				case 'C':C();break;
				case 'D':D();break;
			}
		}
		
		for(int i=0;i<m;i++){
			switch(isu[i]){
				case 0:printf("#");break;
				case 1:printf("A");break;
				case 2:printf("B");break;
				case 3:printf("C");break;
				case 4:printf("D");break;
			}
		}
		puts("");
	}
	return 0;
}