#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;
};
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
p = -1;
getchar();
scanf("%s", a);
len = strlen(a);
struct node *h = build();
front = tail = 0;
qu[tail++] = h;
while(front < tail)
{
struct node *q = qu[front++];
if(q != NULL)
{
printf("%c", q -> data);
if(q -> l != NULL)qu[tail++] = q -> l;
if(q -> r != NULL)qu[tail++] = q -> r;
}
}
printf("\n");
}
return 0;
}