#include <iostream>
#include <cstring>
using namespace std;
struct node{
int val;
node* left;
node* right;
};
void createTree(node *&root)
{
int n;
cin>>n;
if(n==-1) root=NULL;
else
{
root = new node;
root->val = n;
root->left=NULL;
root->right=NULL;
createTree(root->left);
createTree(root->right);
}
}
void printTree(node *root)
{
if(root!=NULL)
{
cout<<root->val<<' ';
printTree(root->left);
printTree(root->right);
}
}
void mirror(node *root)
{
if(root==NULL) return;
if(root->left==NULL && root->right==NULL) return;
node* tmp = root->left;
root->left = root->right;
root->right = tmp;
if(root->left) mirror(root->left);
if(root->right) mirror(root->right);
}
void printTreeFromTopToBottom(node *root)
{
if(!root) return;
queue<node*> q;
q.push(root);
while(q.size()>0)
{
node *tmp = q.front();
q.pop();
cout<<tmp->val<<' ';
if(tmp->left) q.push(tmp->left);
if(tmp->right) q.push(tmp->right);
}
}
int main()
{
node *root = NULL;
createTree(root);
printTree(root);
mirror(root);
printTree(root);
return 0;
}