#include <stdio.h>
#include <stdlib.h>

struct node{
	int id;
	struct node *parentNode;
	struct node *firstChild;
	struct node *sibling;
};

void preorder(struct node* nd);
void inorder(struct node* nd);
void postorder(struct node* nd);
struct node* createNode(int);
struct node* searchNode(int);

struct node* nodes[26];
int n;

int main(){

int i,j;
int id;
int tmpId;
int left, right;
int depth;
struct node* currentNode;
struct node* tmpNode;
struct node* leftChild;
struct node* rightChild;

struct node* root;
	
scanf("%d",&n);
	
for(i=0;i<n;i++){
	
	scanf("%d",&id);
	currentNode = createNode(id);
	
	scanf("%d",&left);
	leftChild = createNode(left);
	scanf("%d",&right);
	rightChild = createNode(right);
	
	if(leftChild){
		leftChild->sibling = rightChild;
		leftChild->parentNode = currentNode;
		currentNode->firstChild = leftChild;
	}
	if(rightChild){
		rightChild->sibling = leftChild;
		rightChild->parentNode = currentNode;
		if(leftChild==NULL) currentNode->firstChild = rightChild;
	}
	
}
	
	// search root
	for(i=0; i<n; i++){
		
		depth = 0;
		tmpNode = nodes[i]->parentNode;
		while(tmpNode){
			depth++;
			tmpNode = tmpNode->parentNode;
		}
		if(depth == 0){
			root = nodes[i];
			break;
		}
		
	}
	
	printf("Preorder\n");
	preorder(root);
	
	printf("\nInorder\n");
	inorder(root);
	
	printf("\npostorder\n");
	postorder(root);

	return 0;
}

void preorder(struct node* nd){
	
	struct node *tmpNode;
	
	printf(" %d",nd->id);
	if(nd->firstChild) preorder(nd->firstChild);
	if(nd->firstChild && nd->firstChild->sibling) preorder(nd->firstChild->sibling);
	
}

void inorder(struct node* nd){
	
	struct node *tmpNode;
	
	if(nd->firstChild) inorder(nd->firstChild);
	printf(" %d",nd->id);
	if(nd->firstChild && nd->firstChild->sibling) inorder(nd->firstChild->sibling);
	
}

void postorder(struct node* nd){
	
	struct node *tmpNode;
	
	if(nd->firstChild) postorder(nd->firstChild);
	if(nd->firstChild && nd->firstChild->sibling) postorder(nd->firstChild->sibling);
	printf(" %d",nd->id);
	
}

struct node* createNode(int id){
	struct node *newNode;
	if(id < 0) return NULL;
	if(newNode = searchNode(id)) return newNode;
	newNode = (struct node*)malloc(sizeof(struct node));
	newNode->id=id;
	newNode->parentNode = NULL;
	newNode->firstChild = NULL;
	newNode->sibling = NULL;
	nodes[id] = newNode;
	return newNode;
}

struct node* searchNode(int id){
	if(nodes[id]) return nodes[id];
	return NULL;
}