/* TU Darmstadt Programming Contest 2001
 * Problem: Automatic Poetry
 * Author : Felix Gaertner
 * Comment:
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>

#define BUFLEN 100

/* getline: read a line into s, return length */
/* taken from Kernighan/Ritchie, p. 29 */
int getline(char s[], int lim) {
    int c, i;

    for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
	s[i] = c;
    if (c == '\n') {
	s[i]=c;
	++i;
    }
    s[i] = '\0';
    return i;
}

int main(void) {

    int n, i, j, scenarios;
    char a[BUFLEN], b[BUFLEN], aa[BUFLEN], bb[BUFLEN];

    int a1, a2, a3, a4, b1;

    /* Read number of scenarios */
    n=scanf("%d\n", &scenarios); assert(n==1);
    assert(scenarios>0);

    while(scenarios--) {
	getline(a, BUFLEN);
	getline(b, BUFLEN);
	fprintf(stderr, "read line a: %s", a);
	fprintf(stderr, "read line b: %s", b);

	i=0;
	while (a[i]!='<') i++;
	a1=i;
	while (a[i]!='>') i++;
	a2=i;
	while (a[i]!='<') i++;
	a3=i;
	while (a[i]!='>') i++;
	a4=i;
	
	i=0;
	while (b[i]!='.') i++;
	b1=i;

	j=0;
	for (i=0; i<a1; i++) 
	    aa[j++] = a[i];
	for (i=a1+1; i<a2; i++)
	    aa[j++] = a[i];
	for (i=a2+1; i<a3; i++)
	    aa[j++] = a[i];
	for (i=a3+1; i<a4; i++)
	    aa[j++] = a[i];
	for (i=a4+1; i<strlen(a); i++)
	    aa[j++] = a[i];
	aa[j]='\0';
	
	j=0;
	for (i=0; i<b1; i++)
	    bb[j++] = b[i];
	for (i=a3+1; i<a4; i++)
	    bb[j++] = a[i];
	for (i=a2+1; i<a3; i++)
	    bb[j++] = a[i];
	for (i=a1+1; i<a2; i++)
	    bb[j++] = a[i];
	for (i=a4+1; i<strlen(a); i++)
	    bb[j++] = a[i];
	bb[j] = '\0';

	printf("%s%s", aa, bb);
    }
    return 0;
}

