#!/usr/bin/python

# Alex Dehnert - 2007-01-27

# Phillips Academy

# Senior-5

# Game of Life simulator for ACSL

 

import sys

 

def parseInput(line):

    """Given an input line, parse it into an easy-to-use dictionary

    """

   

    elems = [ int(elem.strip()) for elem in line.split(',') ]

    birthCount = elems[0]

    births = elems[1:birthCount+1]

    surviveStart = birthCount + 2

    surviveCount = elems[surviveStart - 1]

    surviveEnd = surviveCount + surviveStart

    survive = elems[surviveStart:surviveEnd]

    gens = elems[surviveEnd]

    target = (elems[surviveEnd+1]-1,elems[surviveEnd+2]-1)

    config = {

        'births': births,

        'survive': survive,

        'gens': gens,

        'target': target,

    }

    return config

 

 

class LifeBoard:

    def __init__(self, config, board):

        self.board = board

        #print config

        self.gens = config['gens']

        self.births = config['births']

        self.survive = config['survive']

        self.target = config['target']

        self.curRound = 0

    def doRound(self, ):

        newBoard = []

        b = self.board

        for i in range(0, len(b)):

            newRow = []

            for j in range(0, len(b[i])):

                num = self.countNeighbors(i, j)

                if ((b[i][j] and num in self.survive)

                  or ((not b[i][j]) and num in self.births)):

                    newRow.append(True)

                else: newRow.append(False)

            newBoard.append(newRow)

        self.board = newBoard

        self.curRound += 1

    def run(self, ):

        result = ''

        while self.curRound <= self.gens:

            if(self.board[self.target[0]][self.target[1]]): result += 'A'

            else: result += 'D'

            self.doRound()

            #print self

        return result

    def countNeighbors(self, i, j):

        ret = 0

        b = self.board

        for dx in (-1,0,1):

            for dy in (-1,0,1):

                if(i+dx >= 0 and i+dx < len(b)

                   and j+dy >= 0 and j+dy < len(b[i])

                   and b[i+dx][j+dy]):

                    ret = ret+1

        # But we count the given square, which we shouldn't

        if(b[i][j]): ret = ret - 1

        return ret

    def __str__(self):

        ret = '\n= Board =\n'

        ret += 'Births:  ' + str(self.births) + '\n'

        ret += 'Survive: ' + str(self.survive) + '\n'

        ret += 'Rounds:  ' + str(self.curRound) + ' of ' + str(self.gens) + '\n'

        ret += 'Board:\n' + boardToStr(self.board)

        ret += '= End Board =\n'

        return ret

 

def boardToStr(board):

    ret = ''

    for row in board:

        for elem in row:

            if(elem): ret += '*'

            else: ret += ' '

        ret += '\n'

    return ret

def strToBoard(string):

    ret = []

    stringLines = string.strip('\n').split('\n')

    for rowStr in stringLines:

        row = []

        for cell in rowStr.rstrip('\r\n'):

            row.append(cell == '*')

        ret.append(row)

    return ret

 

defaultBoard = (

"*         \n" +

"*         \n" +

"   *      \n" +

"    *     \n" +

"  *  *   *\n" +

" * **  *  \n" +

"  *     **\n" +

" *       *\n" +

"*        *\n" +

"         *\n")

 

if "__main__" == __name__:

    boardStr = strToBoard(defaultBoard)

    #for line in sys.stdin.readlines():

    if True:

        line = sys.stdin.readline()

        #print "'" + line + "'"

        config = parseInput(line)

        board = LifeBoard(config, boardStr)

        result = board.run()

        print result