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 <vector>
#include <algorithm>
#include <string>
using namespace std;
const int INF = 1 << 28;

int N, M;
void a_sit(string &s) {
  for(int i=0; i<N; i++) {
    if(s[i] == '#') {
      s[i] = 'A';
      return;
    }
  }
}

void b_sit(string &s) {
  for(int i=N-1; i>=0; i--) {
    bool ok = (s[i] == '#');
    ok &= (i+1 >= N or s[i+1] != 'A');
    ok &= (i-1 <  0 or s[i-1] != 'A');

    if(ok) {
      s[i] = 'B';
      return;
    }
  }

  for(int i=0; i<N; i++) {
    if(s[i] == '#') {
      s[i] = 'B';
      return;
    }
  }
}

void c_sit(string &s) {
  for(int i=0; i<N; i++) {
    if(s[i] != '#') {
      if(i+1 < N and s[i+1] == '#') {
        s[i+1] = 'C';
        return;
      }
      if(i-1 >= 0 and s[i-1] == '#') {
        s[i-1] = 'C';
        return;
      }
    }
  }

  s[N/2] = 'C';
  return;
}

void d_sit(string &s) {
  int ma = -1, arg = -1;
  for(int i=0; i<N; i++) {
    if(s[i] != '#') continue;
    int min_dist = INF;
    for(int j=0; j<N; j++) {
      if(i == j or s[j] == '#') continue;
      int dist = (i - j > 0 ? i - j : j - i);
      if(min_dist > dist) {
        min_dist = dist;
      }
    }

    if(min_dist != INF and ma < min_dist) {
      ma = min_dist;
      arg = i;
    }
  }

  if(arg < 0) {
    s[0] = 'D';
  }
  else {
    s[arg] = 'D';
  }
}

void sit_down(char x, string &s) {
  if(x == 'A') a_sit(s);
  if(x == 'B') b_sit(s);
  if(x == 'C') c_sit(s);
  if(x == 'D') d_sit(s);
}

int solve() {
  cin >> N >> M;
  if(N == 0 and M == 0) return 1;

  vector<char> A(M);
  string ans(N, '#');
  for(int i=0; i<M; i++) cin >> A[i];
  for(int i=0; i<M; i++) {
    sit_down(A[i], ans);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  while(!solve());
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define BLANK '#'
int main()
{
  int n,m;
  int i,j,blank,cnt,max;
  bool f;
  char c;
  vector<char> seat;
  while(cin>>n>>m,n|m){
    seat.resize(n);
    for(i=0;i<n;i++)seat[i]=BLANK;
    while(m-->0){
      cin>>c;
      switch(c){
	// A
	case 'A':
	  for(i=0;i<n;i++)
	    if(seat[i]==BLANK){seat[i]=c;break;}
	  break;
	// B
	case 'B':
	  for(i=n;i-->0;){
	    if(seat[i]==BLANK){
	      f=true;
	      if(i+1<n&&seat[i+1]=='A')f=false;
	      if(i>0&&seat[i-1]=='A')f=false;
	      blank=i;
	      if(f){seat[blank]=c;break;}
	    }
	  }
	  if(seat[blank]==BLANK)seat[blank]=c;
	  break;
	// C
	case 'C':
	  f=true;
	  for(i=0;i<n;i++)if(seat[i]!=BLANK)f=false;
	  if(f){seat[n/2]=c;break;}
	  for(i=0;i<n;i++){
	    if(seat[i]!=BLANK){
	      if(i+1<n&&seat[i+1]==BLANK){seat[i+1]=c;break;}
	      if(i>0&&seat[i-1]==BLANK){seat[i-1]=c;break;}
	    }
	  }
	  break;
	// D
	case 'D':
	  max=-1;
	  for(i=0;i<n;i++){
	    if(seat[i]==BLANK){
	      for(cnt=0,j=i;j-->0;cnt++)if(seat[j]!=BLANK)break;
	      if(max<cnt){max=cnt;blank=i;}
	      for(cnt=0,j=i;j++<n;cnt++)if(seat[j]!=BLANK)break;
	      if(max<cnt){max=cnt;blank=i;}
	    }
	  }
	  seat[blank]=c;
	  break;
      }
    }
    for(i=0;i<n;i++)cout<<seat[i];
    cout<<endl;
  }
}