#include<iostream>
#include<cstring>
using namespace std;
typedef struct node;typedef node *tree;
struct node{
char data;
tree Lchild,Rchild;
};
tree bt;int wz=-1;string str;
void build(tree &xtree){ if(str[++wz]!='.'){
xtree=new node; xtree->data=str[wz];
build(xtree->Lchild);
build(xtree->Rchild);
}else xtree=NULL;
}
void Zhong(tree bt){
if(bt){
Zhong(bt->Lchild);
cout<<bt->data;
Zhong(bt->Rchild);
}
}
void Hou(tree bt){
if(bt){
Hou(bt->Lchild);
Hou(bt->Rchild);
cout<<bt->data;
}
}
int main(){
cin>>str;
build(bt);
Zhong(bt);
cout<<endl;
Hou(bt);
return 0;
}