#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char line1[110];
char line2[110];
char s1[100];
char s2[100];
char s3[100];
char s4[100];
char s5[100];
int main()
{
int c;
int i,j,k;
char temp[100];
cin >> c;
getchar();
while(c-->0)
{
memset(line1,0,sizeof(line1));
memset(line2,0,sizeof(line2));
memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
memset(s3,0,sizeof(s3));
memset(s4,0,sizeof(s4));
memset(s5,0,sizeof(s5));
fgets(line1,100,stdin);
fgets(line2,100,stdin);
//cout << line1 ;
//cout << line2 ;
int len = strlen(line1);
int flag1 = 0;
int flag2 = 0;
for(i=0; i<len; i++)
{
if(line1[i] == '<')
break;
s1[i] = line1[i];
}
for(i++,j=0; i<len; i++)
{
if(line1[i] == '>')
break;
s2[j++] = line1[i];
}
for(i++,j=0; i<len; i++)
{
if(line1[i] == '<')
break;
s3[j++] = line1[i];
}
for(i++,j=0; i<len; i++)
{
if(line1[i] == '>')
break;
s4[j++] = line1[i];
}
for(i++,j=0; i<len; i++)
{
s5[j++] = line1[i];
}
cout << s1 << s2 << s3 << s4 << s5;
len = strlen(line2);
for(i=0; i<len; i++)
{
if(line2[i] == '.')
{
break;
}
cout << line2[i];
}
cout << s4 << s3 << s2 << s5;
}
}