#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char a[105];
int p, len;
struct node
{
char data;
struct node *l, *r;
};
struct node *qu[10005];
int front = 0, tail = 0;
struct node *build()
{
p++;
if(p >= len)return NULL;
struct node *h;
if(a[p] == ','){h = NULL;}
else
{
h = (struct node *)malloc(sizeof(struct node));
h -> l = h -> r = NULL;
h -> data = a[p];
h -> l = build();
h -> r = build();
}
return h;
};
void mid_print(struct node *h)
{
if(h == NULL)return ;
mid_print(h -> l);
printf("%c", h -> data);
mid_print(h -> r);
return ;
}
void last_print(struct node *h)
{
if(h == NULL)return ;
last_print(h -> l);
last_print(h -> r);
printf("%c", h -> data);
return ;
}
int main()
{
while(scanf("%s", a) != EOF)
{
getchar();
len = strlen(a);
p = -1;
struct node *h;
h = build();
mid_print(h);
printf("\n");
last_print(h);
printf("\n");
}
return 0;
}