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 <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

int n,m;
int fie[101];
int dist[101];
char data[5]={'#','A','B','C','D',};

int main(void){
	while(1){
		scanf("%d %d",&m,&n);
		if(n+m==0)break;
		memset(fie,0,sizeof(fie));
		for(int i=0;i<n;i++){
			char a;
			scanf("%*c%c",&a);
			if(a=='A'){
				for(int j=0;j<m;j++){
					if(fie[j]==0){
						fie[j]=1;
						break;
					}
				}
			}
			if(a=='B'){
				int j;
				for(j=m-1;j>=0;j--){
					if(j>0 && fie[j-1]==1)continue;
					if(j<m-1 && fie[j+1]==1)continue;
					if(fie[j]==0){
						fie[j]=2;
						break;
					}
				}
				if(j==-1){
					for(int j=0;j<m;j++){
						if(fie[j]==0){
							fie[j]=2;
							break;
						}
					}
				}
			}
			if(a=='C'){
				if(i==0){
					if(n%2==1)fie[(n+1)/2]=3;
					if(n%2==0)fie[n/2+1]=3;
				}else{
					for(int j=0;j<m;j++){
						if(fie[j]!=0){
							if(j<m-1 && fie[j+1]==0){
								fie[j+1]=3;
								break;
							}
							if(j>0 && fie[j-1]==0){
								fie[j-1]=3;
								break;
							}
						}
					}
				}
			}
			if(a=='D'){
				if(i==0){
					fie[0]=4;
				}else{
					for(int j=0;j<m;j++)dist[j]=101;
					for(int j=0;j<m;j++){
						if(fie[j]!=0){
							for(int k=0;k<m;k++){
								dist[k]=min(dist[k],abs(k-j));
							}
						}
					}
					int lll=0;
					for(int j=0;j<m;j++){
						if(dist[j]>dist[lll])lll=j;
					}
					fie[lll]=4;
				}
			}
		}
		for(int i=0;i<m;i++){
			printf("%c",data[fie[i]]);
		}
		printf("\n");
	}
	return 0;
}

C++: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void solve1(string& s, char c) {
	s[s.find('#')] = c;
}
void solve2(string& s) {
	for (int i = s.size() - 1; i >= 0; i--) {
		if (!((i < s.size() - 1 && s[i + 1] == 'A') || (i > 0 && s[i - 1] == 'A'))) {
			s[i] = 'B'; return;
		}
	}
	solve1(s, 'B');
}
vector<int> dist(string& s) {
	vector<int> ret(s.size(), 999999999);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '#') {
			for (int j = 0; j < s.size(); j++) {
				ret[j] = min(ret[j], abs(i - j));
			}
		}
	}
	return ret;
}
void solve3(string &s) {
	vector<int> ret = dist(s);
	for (int i = 0; i < s.size(); i++) {
		if (ret[i] == 1) {
			s[i] = 'C'; return;
		}
	}
	if (s.size() % 2 == 1) s[(s.size() - 1) / 2] = 'C';
	else s[s.size() / 2] = 'C';
}
void solve4(string &s) {
	vector<int> ret = dist(s);
	s[max_element(ret.begin(), ret.end()) - ret.begin()] = 'D';
}
int N, Q;
int main() {
	while (cin >> N >> Q, N) {
		string s(N, '#'), t;
		while (Q--) {
			cin >> t;
			if (t == "A") solve1(s, 'A');
			if (t == "B") solve2(s);
			if (t == "C") solve3(s);
			if (t == "D") solve4(s);
		}
		cout << s << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int seki[101];

main(){
  int m,n;
  while(cin>>n>>m,n|m){
    string seat;
    rep(i,n)seat+='#';

    rep(i,m){
      //cout<<seat<<endl;
      char c;
      int pos=0;
      cin>>c;
      switch(c){
      case 'A':
	pos=0;
	while(seat[pos]!='#')++pos;
	seat[pos]='A';
	break;
      case 'B':
	pos=n-1;
	while(true){
	  if(pos<0)break;
	  if(seat[pos]!='#'){
	    --pos;
	    continue;
	  }
	  if(pos && seat[pos-1]=='A'){
	    --pos;
	    continue;
	  }
	  if(pos+1<n && seat[pos+1]=='A'){
	    --pos;
	    continue;
	  }
	  seat[pos]='B';
	  break;
	}
	if(pos==n){
	  pos=0;
	  while(seat[pos]!='#')++pos;
	  seat[pos]='B';
	}
	break;
      case 'C':
	if(i==0){
	  if(n%2)seat[(n+1)/2-1]='C';
	  else seat[n/2]='C';
	}else{
	  pos=0;
	  while(seat[pos]!='#')++pos;
	  seat[pos]='C';
	}
	break;
      case 'D':
	if(i==0){
	  seat[0]='D';
	  continue;
	}
	memset(seki,0,sizeof(0));
	int maxt=0,maxpos=0;

	if(seat[0]=='#'){
	  seki[0]=1;
	  maxt=1;
	  maxpos=1;
	}
	pos=1;
	while(pos<n){
	  if(seat[pos]=='#')seki[pos]=seki[pos-1]+1;
	  else seki[pos]=0;
	  if(seki[pos]>maxt){
	    maxt=seki[pos];
	    maxpos=pos;
	  }
	  ++pos;
	}
	//rep(j,n)cout<<seki[j]<<" ";
	//cout<<endl;
	//cout<<maxpos<<" "<<maxt<<endl;
	if(maxpos==n-1)seat[n-1]='D';
	else if(maxpos==maxt-1)seat[0]='D';
	else if(maxt%2)seat[maxpos-maxt/2]='D';
	else seat[maxpos-maxt/2]='D';
	break;
      }
    }
    cout<<seat<<endl;
  }
}