# David Ionita
# Bergen County Academies
# Intermediate Division

import copy

PRIME = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
SQUARES = [9, 16, 25, 36, 49]

token = open("4int_sampledata.txt", "r")

for c in range(5):
    try:
        case = token.readline().strip().split()
        answer = ""

        opponent = [int(case[0]), int(case[1]), int(case[2])]
        player = [int(case[3]), int(case[4]), int(case[5])]
        all = player + opponent
        # player 1 2 3, opponent 1 2 3

        dice = []
        for i in range(int(case[6])):
            dice.append(int(case[7+i]))

            # MAKE SURE UPDATE BOTH PLAYER AND ALL ARRAYS

            currentDice = int(case[7+i])
            cPvalue = min(player[0], player[1], player[2])
            cPindex = player.index(cPvalue)
            others = copy.deepcopy(all)
            others.remove(cPvalue)

            cPafterRoll = cPvalue + currentDice

            if (cPafterRoll in others):
                cPafterRoll = cPvalue

            elif (cPafterRoll in PRIME):

                if (cPafterRoll > 52):
                    cPafterRoll = cPvalue
                elif cPafterRoll+1 in others:
                    cPafterRoll += 0
                elif cPafterRoll+2 in others:
                    cPafterRoll += 1
                elif cPafterRoll+3 in others:
                    cPafterRoll += 2
                elif cPafterRoll+4 in others:
                    cPafterRoll += 3
                elif cPafterRoll+5 in others:
                    cPafterRoll += 4
                elif cPafterRoll+6 in others:
                    cPafterRoll += 5
                else:
                    if (cPafterRoll+6 <= 52): # edge case -- go to before PRIME's +6 if over 52?
                        cPafterRoll += 6

            elif (cPafterRoll in SQUARES):

                if (cPafterRoll > 52):
                    cPafterRoll = cPvalue
                elif cPafterRoll - 1 in others:
                    cPafterRoll -= 0
                elif cPafterRoll - 2 in others:
                    cPafterRoll -= 1
                elif cPafterRoll - 3 in others:
                    cPafterRoll -= 2
                elif cPafterRoll - 4 in others:
                    cPafterRoll -= 3
                elif cPafterRoll - 5 in others:
                    cPafterRoll -= 4
                elif cPafterRoll - 6 in others:
                    cPafterRoll -= 5
                else:
                    cPafterRoll -= 6

            # 6-8 11-13 16-18 21-23 26-28 34-36 39-41 44-46 49-51
            elif (cPvalue <= 6 and cPafterRoll >= 8) or (cPvalue <= 11 and cPafterRoll >= 13) or (
                    cPvalue <= 16 and cPafterRoll >= 18) or (cPvalue <= 21 and cPafterRoll >= 23) or (
                    cPvalue <= 26 and cPafterRoll >= 28) or (cPvalue <= 34 and cPafterRoll >= 36) or (
                    cPvalue <= 39 and cPafterRoll >= 41) or (cPvalue <= 44 and cPafterRoll >= 46) or (
                    cPvalue <= 49 and cPafterRoll >= 51):

                temp_cPafterRoll = cPvalue
                for j in range(cPvalue, cPafterRoll+1):
                    if (j % currentDice == 0) and (not (j in others)):
                        temp_cPafterRoll = j
                cPafterRoll = temp_cPafterRoll

            if (cPafterRoll == 52):
                cPafterRoll = 9999

            player[cPindex] = cPafterRoll
            all[cPindex] = cPafterRoll

        player.sort()
        for k in range(len(player)):
            if (player[k] < 52):
                answer = answer + " " + str(player[k])
        if (answer == ""):
            answer = "GAME OVER"
        print(answer)

    except:
        print("GAME OVER")