#include<bits/stdc++.h>
using namespace std;
struct TreeNode{
char data;
TreeNode* left;
TreeNode* right;
TreeNode(char c): data(c), left(NULL), right(NULL){}
};
void buildTree(TreeNode* &root, string &str){
//递归终止条件
if(str.empty())return ;
if(str[0] == '#'){
str.erase(0, 1);
return ;
}
//继续递归
root = new TreeNode(str[0]);//生成新结点
str.erase(0, 1);
buildTree(root->left, str);
buildTree(root->right, str);
}
void traverse_inorder(TreeNode* root){
//递归终止条件
if(root == NULL)return ;
//继续递归
traverse_inorder(root->left);
cout << root->data <<' ';
traverse_inorder(root->right);
}
int main(){
string input = "";
TreeNode* tree = NULL;
while(cin >> input){
delete tree;//释放指针所指内存
tree = NULL;//指针置NULL
//前序构造二叉树
buildTree(tree, input);
//中序遍历
traverse_inorder(tree);
}
return 0;
}