# Name: Angelika Wang
# Team: We Sense
# Intermediate Division
# ACSL Contest #4
# Date of Program: 4/27/2020
# Grade: 8th
# Language: Python
# Input Data Method: interactively key in

def checkPrime(num):  
    if num<=1: 
        return False
    if num<=3: 
        return True
    i = 2
    while i*i <= num: 
        if num % i == 0: 
            return False
        i = i + 1
    return True
    
def checkSquare(num):
    if num<=4:
        return False
    i = 3 
    while i*i <= num:
        if i*i == num:
            return True
        i = i+1
    return False

def checkHV(start,end):
    for x in range(0,len(horzvert)):
        if start<=horzvert[x][0] and end>=horzvert[x][1]:
            return True
    return False
    
def prime(endLoc):
    for y in range(1,7):
        if endLoc+y>52 and y<6:
            return endLoc
        if (endLoc+y in opponent) or (endLoc+y in player):
            stop = endLoc+y-1
            return stop
    stop = endLoc + 6
    return stop

def square(endLoc):
    for y in range(1,7):
        if (endLoc-y in opponent) or (endLoc-y in player):
            stop = endLoc-y+1
            return stop
    stop = endLoc - 6
    return stop
    
def HV(start,end,val):
    for z in range(start,end+1):
        if (z%val == 0) and (z not in player) and (z not in opponent):
            return z
    return start


for repeates in range(0,5):
    info = input().strip()
    info = info.split(' ')
    info = [int(number) for number in info]
    opponent = info[0:3]
    player = info[3:6]
    numRolls = info[6]
    rollVals = info[7:]
    opponent.sort()
    player.sort()
    horzvert = [[11,13],[16,18],[21,23],[26,28],[34,36],[39,41],[44,46],[49,51]]

    for diceRoll in range(0,numRolls):
        if len(player)==0:
            print('GAME OVER')
            break
        else:
            land = player[0]+rollVals[diceRoll]
            if land == 52:
                player.remove(player[0])
            elif land >52:
                continue
            elif (land not in player) and (land not in opponent):
                if checkPrime(land):
                    player[0] = prime(land)
                elif checkSquare(land):
                    player[0] = square(land)
                elif checkHV(player[0],land):
                    player[0] = HV(player[0],land,rollVals[diceRoll])
                else:
                    player[0] = land
            player.sort()

    if len(player) > 0:
        player.sort()
        player = [str(location) for location in player]
        print(' '.join(player))