#include <cstddef>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
struct BinaryT{
char data;
struct BinaryT* lchild;
struct BinaryT* rchild;
BinaryT(char c):data(c),lchild(NULL),rchild(NULL){}
};
BinaryT* buildt(string x,int& position){
if(x[position]=='#'){
position++;
return NULL;
}
BinaryT* root=new BinaryT(x[position++]);
root->lchild=buildt(x, position);
root->rchild=buildt(x, position);
return root;
}
void midOrder(BinaryT* root){
if(root==NULL) return;
midOrder(root->lchild);
cout<<root->data<<' ';
midOrder(root->rchild);
}
int main() {
string x;
while(cin>>x){
int position=0;
BinaryT* r=buildt(x, position);
midOrder(r);
}
}