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
		}
		chair := make([]string, n+1)
		for i := range chair {
			chair[i] = "#"
		}
		chair[n] = "Sentinel"
		for i := 0; i < m; i++ {
			scanner.Scan()
			switch who := scanner.Text(); who {
			case "A": // 左から眺めて行って空いている席があったら即座に座る
				for j := 0; j < n; j++ {
					if chair[j] == "#" {
						chair[j] = "A"
						break
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "B":
				flag := true
				// 右端からAの隣でない席を探していく
				for j := n-1; j > -1; j-- {
					if chair[j] == "#" && (j == 0 || chair[j-1] != "A") && chair[j+1] != "A" {
						flag = false
						chair[j] = "B"
						break
					}
				}
				// Aの隣しか空いていないので一番左端の空いている席に座る
				if flag {
					for j := 0; j < n; j++ {
						if chair[j] == "#" {
							chair[j] = "B"
							break
						}
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "C":
				if i == 0 {
					chair[n/2] = "C" // 先客が誰もいないときは真ん中の椅子に座る
				} else {
					for j := 0; j < n; j++ { // 左から舐めて
						if chair[j] != "#" { // その席が空いていなくて
							if chair[j+1] == "#" { // 右隣が空いているなら座る
								chair[j+1] = "C"
								break
							} else if j != 0 && chair[j-1] == "#" { // 右隣が空いていないので左隣に座る
								chair[j-1] = "C"
								break
							}
						}
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "D":
				distanceTable := make([]int ,n)
				for j := range distanceTable {
					distanceTable[j] = INF
				}
				for j:= 0; j < n; j++ {
					if chair[j] != "#" {
						for k := 0; k < n; k++ {
							distanceTable[k] = min(distanceTable[k], abs(j-k))
						}
					}
				}
				// log.Println("distanceTAble:", distanceTable)
				at := 0
				distance := 0
				for j := 0; j < n; j++ {
					if distance < distanceTable[j] {
						at = j
						distance = distanceTable[j]
					}
				}
				chair[at] = "D"
				// log.Println(chair)
				break // 次の人を読み込む
			}
		}
		fmt.Println(strings.Join(chair, ""))
	}
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

Python: while 1:
    N, M = map(int, input().split())
    if N == M == 0:
        break
    ans = ["#"]*N
    for i in range(M):
        a = input()
        if a == 'A':
            for j in range(N):
                if ans[j] == '#':
                    ans[j] = 'A'
                    break
        elif a == 'B':
            for j in range(N-1, -1, -1):
                if ans[j] == '#':
                    if (j == 0 or ans[j-1] != 'A') and (j == N-1 or ans[j+1] != 'A'):
                        ans[j] = 'B'
                        break
            else:
                for j in range(N):
                    if ans[j] == '#':
                        ans[j] = 'B'
                        break
        elif a == 'C':
            if i:
                for j in range(N):
                    if ans[j] != '#':
                        if j < N-1 and ans[j+1] == '#':
                            ans[j+1] = 'C'
                            break
                        if j > 0 and ans[j-1] == '#':
                            ans[j-1] = 'C'
                            break
            else:
                ans[N//2] = 'C'
        else:
            if i:
                d = 0; k = -1
                for j in range(N):
                    if ans[j] == '#':
                        d0 = N
                        p = j
                        while p >= 0 and ans[p] == '#':
                            p -= 1
                        if p >= 0:
                            d0 = min(d0, j-p)
                        q = j
                        while q < N and ans[q] == '#':
                            q += 1
                        if q < N:
                            d0 = min(d0, q-j)
                        if d < d0:
                            k = j; d = d0
                ans[k] = 'D'
            else:
                ans[0] = 'D'
    print(*ans, sep='')

Python: def solve():
    from sys import stdin
    f_i = stdin
    
    ans = ''
    
    while True:
        n, m = map(int, f_i.readline().split())
        
        if n == 0 and m == 0:
            break
        
        chairs = '#' * n
        
        for i in range(m):
            a = f_i.readline().rstrip()
            if a == 'A':
                chairs = chairs.replace('#', 'A', 1)
            elif a == 'B':
                chairs = chairs[::-1]
                idx = chairs.find('#')
                while idx != -1:
                    if idx > 0:
                        if chairs[idx-1] == 'A':
                            idx = chairs.find('#', idx + 1)
                            continue
                    if idx < n - 1:
                        if chairs[idx+1] == 'A':
                            idx = chairs.find('#', idx + 1)
                            continue
                    chairs = chairs[:idx] + 'B' + chairs[idx+1:]
                    chairs = chairs[::-1]
                    break
                else:
                    chairs = chairs[::-1]
                    chairs = chairs.replace('#', 'B', 1)
            elif a == 'C':
                if chairs.count('#') == n:
                    idx = n // 2
                    chairs = chairs[:idx] + 'C' + chairs[idx+1:]
                else:
                    idx = n
                    for c in 'ABCD':
                        i = chairs.find(c)
                        if i != -1:
                            idx = min(idx, i)
                    if idx == 0:
                        idx = chairs.find('#', idx + 1)
                    else:
                        if chairs[idx+1] == '#':
                            idx += 1
                        else:
                            idx -= 1
                    chairs = chairs[:idx] + 'C' + chairs[idx+1:]
            else:
                if chairs.count('#') == n:
                    chairs = 'D' + chairs[1:]
                else:
                    dist1 = [0] * n
                    d = n
                    for i, c in enumerate(chairs):
                        if c == '#':
                            d += 1
                            dist1[i] = d
                        else:
                            d = 0
                            dist1[i] = d
                    
                    dist2 = [0] * n
                    d = n
                    for i, c in enumerate(chairs[::-1], 1):
                        if c == '#':
                            d += 1
                            dist2[-i] = d
                        else:
                            d = 0
                            dist2[-i] = d
                    
                    dist = []
                    for d1, d2 in zip(dist1, dist2):
                        dist.append(min(d1, d2))
                    
                    idx = dist.index(max(dist))
                    
                    chairs = chairs[:idx] + 'D' + chairs[idx+1:]
        
        ans += chairs
        ans += '\n'
    
    print(ans, end='')

solve()