
#include <bits/stdc++.h>
using namespace std;
int i;
char a[55];
typedef struct Tree
{
char data;
Tree *Lchild;
Tree *Rchild;
}Tree,*BiTree;
BiTree Creat()
{
BiTree root;
char c=a[i++];
if(c==',')
{
root=NULL;
}
else
{
root=(BiTree)malloc(sizeof(BiTree));
root->data=c;
root->Lchild=Creat();
root->Rchild=Creat();
}
return root;
}
void zhong(BiTree root)
{
if(root)
{
zhong(root->Lchild);
cout<<root->data;
zhong(root->Rchild);
}
}
void hou(BiTree root)
{
if(root)
{
hou(root->Lchild);
hou(root->Rchild);
cout<<root->data;
}
}
int main()
{
BiTree root;
while(~scanf("%s",a))
{
i=0;
root=Creat();
zhong(root);
printf("\n");
hou(root);
printf("\n");
}
return 0;
}