{$R+,Q+}
{$minstacksize 30000000}
program highways;

uses
	sysutils, math;

const
	maxn = 1500;

type
	tcity = record
		x, y, i: smallint;
		ang: double;
	end;

	tcityarr = array [1..maxn] of tcity;

var
	n: longint;
	name: array [1..maxn] of string;
	x, y: array [1..maxn] of longint;
	a, b: array [1..maxn] of longint;
	visited: array [1..maxn] of boolean;
	c: tcityarr;
	p: array [1..maxn] of longint;
	size: array [1..maxn] of longint;
	ch: array [1..maxn, 1..maxn] of longint;
	chn: array [1..maxn] of longint;
	which: array [1..maxn] of longint;

procedure dfs(i, j: longint);
var
	k: longint;
begin
	p[i] := j;
	visited[i] := true;
	size[i] := 1;
	for k := 1 to n - 1 do begin
		if (a[k] = i) and not visited[b[k]] then begin
			dfs(b[k], i);
			size[i] := size[i] + size[b[k]];
		end;
		if (b[k] = i) and not visited[a[k]] then begin
			dfs(a[k], i);
			size[i] := size[i] + size[a[k]];
		end;
	end;
end;

procedure sort(var c: tcityarr; l, r: longint);
var
	i, j: longint;
	x: extended;
	t: tcity;
begin
	i := l;
	j := r;
	x := c[i + random(j - i + 1)].ang;
	while i <= j do begin
		while c[i].ang < x do inc(i);
		while c[j].ang > x do dec(j);
		if i <= j then begin
			t := c[i]; c[i] := c[j]; c[j] := t;
			inc(i);
			dec(j);
		end;
	end;
	if l < j then sort(c, l, j);
	if i < r then sort(c, i, r);
end;

procedure hang(v: longint; var c: tcityarr; n: longint);
var
	d: tcityarr;
	xmin, ymin: longint;
	i, j, k: longint;
	t: tcity;
begin
	ymin := c[1].y;
	xmin := c[1].x;
	j := 1;
	for i := 2 to n do begin
		if (c[i].y < ymin) or ((c[i].y = ymin) and (c[i].x < xmin)) then begin
			ymin := c[i].y;
			xmin := c[i].x;
			j := i;
		end;
	end;
	t := c[j]; c[j] := c[1]; c[1] := t;
	which[v] := c[1].i;
	for i := 2 to n do begin
		c[i].ang := arctan2(c[i].y - ymin, c[i].x - xmin);
	end;
	sort(c, 2, n);
	j := 2;
	for i := 1 to chn[v] do begin
		for k := 1 to size[ch[v][i]] do begin
			d[k] := c[j];
			inc(j);
		end;
		hang(ch[v][i], d, size[ch[v][i]]);
	end;
end;

var
	i, j, k: longint;

begin
	reset(input, 'highways.in');
	rewrite(output, 'highways.out');

	readln(n);
	assert((2 <= n) and (n <= maxn));
	for i := 1 to n do begin
		readln(name[i]);
		assert((1 <= length(name[i])) and (length(name[i]) <= 60));
		for j := 1 to i - 1 do
			assert(name[i] <> name[j]);
		for j := 1 to length(name[i]) do
			assert(name[i][j] in [#33..#127]);
		assert(trim(name[i]) = name[i]);

		readln(x[i], y[i]);
		assert(abs(x[i]) <= 10000);
		assert(abs(y[i]) <= 10000);
	end;

	for i := 1 to n do begin
		k := 1;
		for j := 1 to n do if i <> j then begin
			c[k].ang := arctan2(y[i] - y[j], x[i] - x[j]);
			inc(k);
		end;
		sort(c, 1, n - 1);
		for j := 1 to n - 2 do begin
			assert(abs(c[j].ang - c[j + 1].ang) > 1e-9);
		end;
	end;

	for i := 1 to n - 1 do begin
		readln(a[i], b[i]);
		assert(a[i] <> b[i]);
		assert((1 <= a[i]) and (a[i] <= n));
		assert((1 <= b[i]) and (b[i] <= n));
	end;

	dfs(1, 0);
	for i := 1 to n do 
		assert(visited[i]);

	for i := 2 to n do begin
		inc(chn[p[i]]);
		ch[p[i]][chn[p[i]]] := i;
	end;

	for i := 1 to n do begin
		c[i].x := x[i];
		c[i].y := y[i];
		c[i].i := i;
	end;
	hang(1, c, n);

	for i := 1 to n do begin
		writeln(name[which[i]]);
	end;

	close(input);
	close(output);
end.