from math import sqrt

asteroides = open("ChampsAsteroides.txt").read()

input = """688.84, 515.91, -158.86
-482.17, 22.55, -190.13
567.6, -393.37, -46.81
166.76, 816.23, 9.37
-436.32, 511.61, 236.74
-498.99, 819.49, 965.57
620.43, 804.33, -379.7
459.66, 797.68, 367.97
-55.71, -798.6, -131.66
221.77, 826.02, 933.21"""

def distance(trajet, objet):
    point_a = trajet[0]
    point_b = trajet[1]
    x_a = point_a[0]
    y_a = point_a[1]
    z_a = point_a[2]
    x_b = point_b[0]
    y_b = point_b[1]
    z_b = point_b[2]
    x_o = objet[0]
    y_o = objet[1]
    z_o = objet[2]
    delta_x = x_b - x_a
    delta_y = y_b - y_a
    delta_z = z_b - z_a
    d_min = 999999
    iter = 1000
    for i in range(iter):
        x = x_a + i*delta_x/iter
        y = y_a + i*delta_y/iter
        z = z_a + i*delta_z/iter
        d = sqrt((x_o-x)**2 + (y_o-y)**2 + (z_o - z)**2) 
        d_min = min(d_min, d)
    return d_min

asteroides = [v.replace(":", ",").replace(" ", "") for v in asteroides.splitlines()]
asteroides = [v.split(",") for v in asteroides]
asteroides = {v[0]:[(float(v[1]), float(v[2]), float(v[3])), 999999] for v in asteroides}

trajet = list()
input = input.splitlines()
for i in range(len(input)-1):
    point_a = tuple(float(v) for v in input[i].replace(" ", "").split(","))
    point_b = tuple(float(v) for v in input[i+1].replace(" ", "").split(","))
    trajet.append(((point_a[0], point_a[1], point_a[2]), (point_b[0], point_b[1], point_b[2])))

for t in trajet:
    for a in asteroides:
        asteroides[a][1] = min(asteroides[a][1], distance(t, asteroides[a][0]))


solution = [k for k, v in sorted(asteroides.items(), key=lambda item: item[1][1])]
for i in range(9):
    print('"'+solution[i]+'"', end=", ")