import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class highways_pm {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(new File("highways.in"));
        PrintWriter writer = new PrintWriter(new File("highways.out"));

        int n = scanner.nextInt();
        scanner.nextLine();
        City[] c = new City[n];
        for (int i = 0; i < c.length; i++) {
            c[i] = new City(
                    scanner.nextLine(),
                    scanner.nextInt(),
                    scanner.nextInt());
            scanner.nextLine();
        }
        Vertex[] v = new Vertex[n];
        for (int i = 0; i < v.length; i++) {
            v[i] = new Vertex();
            v[i].index = i;
        }

        for (int i = 0; i < n - 1; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            a--;
            b--;
            v[a].neighbours.add(v[b]);
            v[b].neighbours.add(v[a]);
        }

        v[0].dfs();
        int ii = 0;
        for (int i = 1; i < n; i++) {
            if (c[i].x < c[ii].x) ii = i;
        }

        List<City> cc = new ArrayList<City>(n - 1);
        for (City city : c) {
            if (city != c[ii]) {
                cc.add(city);
            }
        }
        c[ii].assign(v[0], cc);

        Arrays.sort(c, new Comparator<City>() {
            public int compare(City o1, City o2) {
                return o1.ind - o2.ind;
            }
        });
        for (City city : c) {
            writer.println(city.name);
        }
        writer.close();
/*
                
        int[] x = new int[n];
        int[] y = new int[n];
        for (City city : c) {
            x[city.ind] = city.x;
            y[city.ind] = city.y;
        }
        for (Vertex v1 : v) {
            for (Vertex v2 : v1.neighbours) if (v2.index > v1.index) {
                System.out.println("draw(" + x[v1.index] + "un, " + y[v1.index] + "un)--(" + x[v2.index] + "un, " + y[v2.index] + "un);");
            }
        }
        for (City city : c) {
            System.out.println("label(\"" + city.name + "\", (" + city.x + "un, " + city.y + "un));");
        }
        */
    }

    static class City implements Comparator<City>{
        String name;
        int x;
        int y;
        int ind;

        public City(String name, int x, int y) {
            this.name = name;
            this.x = x;
            this.y = y;
        }

        void assign(Vertex v, List<City> cities) {
            ind = v.index;
            Collections.sort(cities, this);
            int i = 0;
            for (Vertex vv : v.neighbours) {
                if (vv != v.parent) {
                    List<City> cc = new ArrayList<City>(vv.vertexNumber);
                    for (int j = i + 1; j < i + vv.vertexNumber; j++) {
                        cc.add(cities.get(j));
                    }
                    cities.get(i).assign(vv, cc);
                    i = i + vv.vertexNumber;
                }
            }
        }

        public int compare(City a, City b) {
            int dx1 = a.x - x;
            int dx2 = b.x - x;
            int dy1 = a.y - y;
            int dy2 = b.y - y;
            return dx1 * dy2 - dx2 * dy1;
        }
    }

    static class Vertex {
        Collection<Vertex> neighbours = new ArrayList<Vertex>();
        int index;

        Vertex parent;
        int vertexNumber;

        public void dfs() {
            vertexNumber = 1;
            for (Vertex v : neighbours) {
                if (v != parent) {
                    v.parent = this;
                    v.dfs();
                    vertexNumber += v.vertexNumber;
                }
            }
        }
    }
}
