#include <iostream>
using namespace std;
int a[100002][2];
int x, y, z, root;
int n;
void preorder(char c)
{
cout << c;
if(a[c][0] != '*')
{
preorder(a[c][0]);
}
if(a[c][1] != '*')
{
preorder(a[c][1]);
}
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> x >> y >> z;
if(i == 1)
{
root = x;
}
a[x][0] = y;
a[x][1] = z;
}
preorder(root);
return 0;
}