/** Problem: highways
  * Solution by: Semyon Dyatlov
  **/
#include <algorithm>
#include <stdio.h>

#define for if (0) ; else for

#define MAXN 1500

using namespace std;

int n, x[MAXN], y[MAXN], i0, z[MAXN], ec[MAXN], e[MAXN][MAXN], c[MAXN];
char name[MAXN][100];
char buffer[16384];

bool less(const int &a, const int &b)
{
  return (x[a]-x[i0])*(y[b]-y[i0])>(x[b]-x[i0])*(y[a]-y[i0]);
}

void count(int a, int p)
{
  c[a] = 1;
  for (int i=0;i<ec[a];i++)
    if (e[a][i]!=p)
    {
      count(e[a][i],a);
      c[a] += c[e[a][i]];
    }
}

void go(int a, int p, int q, int *v)
{
  z[a] = q;
  i0 = q;
  stable_sort(v,v+c[a]-1,less);
  int cur = 0;
  for (int i=0;i<ec[a];i++)
    if (e[a][i]!=p)
    {
      go(e[a][i],a,v[cur],v+cur+1);
      cur += c[e[a][i]];
    }
}

int main()
{
  freopen("highways.in","rt",stdin);
  freopen("highways.out","wt",stdout);

  gets(buffer);
  sscanf(buffer,"%d",&n);
  for (int i=0;i<n;i++)
  {
    gets(name[i]);
    gets(buffer);
    sscanf(buffer,"%d%d",&x[i],&y[i]);
  }
  for (int i=1;i<n;i++)
  {
    int a, b;
    gets(buffer);
    sscanf(buffer,"%d%d",&a,&b);
    --a;
    --b;
    e[a][ec[a]++] = b;
    e[b][ec[b]++] = a;
  }

  int best = 0;
  for (int i=1;i<n;i++)
    if (x[i]<x[best]||(x[i]==x[best]&&y[i]<y[best]))
      best = i;
  count(0,-1);
  static int v[MAXN];
  for (int i=0;i<n-1;i++)
    v[i] = i+(i>=best);
  go(0,-1,best,v);

  for (int i=0;i<n;i++)
    printf("%s\n",name[z[i]]);

  return 0;
}