// : i !, vc6.0
/*#include <stdio.h>
#include <string.h>
#define MAX 105
int main()
{
char l1[MAX],l2[MAX],c1[MAX],c2[MAX];
char s1[MAX],s2[MAX],s3[MAX],s4[MAX],s5[MAX],s[MAX];
int len1,len2,len3,len4,len5,len,n;
scanf("%d",&n);
getchar();
while(--n>=0)
{
fgets(l1,sizeof(l1),stdin);
fgets(l2,sizeof(l2),stdin);
int flag=1;
len1=len2=len3=len4=len5=len=0;
for(int i=0;l1[i]!='
';i++)
{
if(l1[i]=='<' || l1[i]=='>')
{
flag++;
continue;
}
switch(flag)
{
case 1:
s1[len1++]=l1[i];
break;
case 2:
s2[len2++]=l1[i];
break;
case 3:
s3[len3++]=l1[i];
break;
case 4:
s4[len4++]=l1[i];
break;
case 5:
s5[len5++]=l1[i];
break;
}
}
s1[len1]=s2[len2]=s3[len3]=s4[len4]=s5[len5]='\0';
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
sprintf(c1,"%s%s%s%s%s",s1,s2,s3,s4,s5);
//printf("%s
",c1);
for(int i=0;l2[i+3]!='
';i++)
{
if(l2[i]=='.' && l2[i+1]=='.' && l2[i+2]=='.')
break;
s[len++]=l2[i];
}
s[len]='\0';
sprintf(c2,"%s%s%s%s%s",s,s4,s3,s2,s5);
//printf("%c
",c2);
printf("%s
%s
",c1,c2);
}
return 0;
}*/
// --C++
/*#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cin>>n;
getchar();
for(int cas=1;cas<=n;cas++)
{
string l1,l2;
int pos[6];
int j=1;
pos[0]=-1;
getline(cin,l1);
for(int i=0;l1[i];i++)
{
if(l1[i]=='<' || l1[i]=='>')
{
pos[j++]=i;// j
}
else
cout<<l1[i];
}
cout<<endl;
getline(cin,l2);
for(int i=0;l2[i];i++)
{
if(l2[i]=='.')
break;
else
cout<<l2[i];
}
int k;
for(k=pos[3]+1;k<pos[4];k++)
cout<<l1[k];
for(k=pos[2]+1;k<pos[3];k++)
cout<<l1[k];
for(k=pos[1]+1;k<pos[2];k++)
cout<<l1[k];
for(k=pos[4]+1;l1[k];k++)
cout<<l1[k];
cout<<endl;
}
return 0;
}*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
long n;
cin>>n;
getchar();
for(long cas=1;cas<=n;cas++)
{
string a,b,ans;
getline(cin,a);
for(long i=0;a[i];i++)
if(a[i]!='<'&&a[i]!='>')
cout<<a[i];
cout<<endl;
// Print the First Line
getline(cin,b);
// Read In stringA and stringB
long j,pos[5]={0};
j=0;
for(long i=0;a[i];i++)
if(a[i]=='<'||a[i]=='>')
{
j++;
pos[j]=i;
}
// Get Four Positions
string _1="",_2="",_3="",_4="";
for(long i=pos[1]+1;i<=pos[2]-1;i++)
_1+=a[i];
for(long i=pos[2]+1;i<=pos[3]-1;i++)
_2+=a[i];
for(long i=pos[3]+1;i<=pos[4]-1;i++)
_3+=a[i];
for(long i=pos[4]+1;a[i];i++)
_4+=a[i];
ans="";
for(long i=0;b[i];i++)
{
if(b[i]!='.')
ans+=b[i];
else
{
ans+=_3+_2+_1+_4;
break;
}
}
cout<<ans<<endl;
// Print the Secont Line
}
return 0;
}