#include<iostream>
#include<string>
using namespace std;
struct node{
	char data;
	node *lch,*rch;
};
void creat(node*p,string str,int r)
{
	p->data=str[r];
	if(str[2*r+1]=='#'||r*2+1>str.size()-1)
		p->lch=NULL;
	else 
	{
		p->lch=new node;
		creat(p->lch,str,r*2+1);
	}
	if(str[2*r+2]=='#'||r*2+2>str.size()-1)
		p->rch=NULL;
	else
	{
		p->rch=new node;
		creat(p->rch,str,r*2+2);
	}
}

void  PreOrder(node *root)
{   
	if (root!=NULL)   
	{     
		cout<<root->data;      
		PreOrder(root ->lch);  
		PreOrder(root ->rch);    
	}
}
int main()
{
	int n;
	node*p=new node;
	node*head;
	head=p;
	string str;
	while(cin>>n)
	{
		while(n--)
		{
			while(cin>>str)
			{
				if(str[0]!='#')
				{
					creat(p,str,0);
					PreOrder(head);
					cout<<endl;
				}
			}
		}
	}
	return 0;
}