#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
    char name[50];
    int score;
    struct node *left,*right;
};
struct node* newnode(int score,char name[])
{
    struct node* node=(struct node*)malloc(sizeof(struct node));
    strcpy(node->name,name);
    node->score = score;
    node->left = node->right =NULL;
    return node;
}
struct node* insert(struct node* root,int score,char name[])
{
    if(root == NULL)
    return newnode(name,score);
    if(score<root->score)
    root->left = insert(root->left,name,score);
    else
    root->right = insert(root->right,name,score);
    
    return root;
}

void preorder(struct node* root)
{
    if(root)
    {
        printf("%s %d",root->name,root->score);
        preorder(root->left);
        preorder(root->right);
    }
}
void inorder(struct node* root)
{
    if(root)
    {
        inorder(root->left);
         printf("%s %d",root->name,root->score);
        inorder(root->right);
    }
}
void postorder(struct node* root)
{
    if(root)
    {
        postorder(root->left);
        postorder(root->right);
        printf("%s %d",root->name,root->score);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n<=0)
    {
        printf("Invalid input");
        return 0;
    }
    char name[50];
    int score;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&score);
        root = insert(root,name,score);
    }
   
    preorder(root);
    
     inorder(root);
   
     postorder(root);
   
    
return 0;
}