/* TU Darmstadt Programming Contest 2001
 * Problem: Automatic Poetry
 * Author : Stefan Maier
 * Comment:
 */
import java.io.*;
import java.util.*;

public class poetry {

    protected static BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );

	public static void main( String args[ ] ) {
	
		String i1, i2, s1, s2, s3, s4, s5;
		int maxcount=0;
		
		try { 
		    maxcount=Integer.parseInt(in.readLine());

		    for(int count=0;count<maxcount;count++){
			//read input lines
			i1 = in.readLine();
			i2 = in.readLine();

			//generate output
			s1 = i1.substring(0,i1.indexOf("<"));
			s2 = i1.substring(i1.indexOf("<")+1,i1.indexOf(">"));
			s3 = i1.substring(i1.indexOf(">")+1,i1.lastIndexOf("<"));
			s4 = i1.substring(i1.lastIndexOf("<")+1, i1.lastIndexOf(">"));
			s5 = i1.substring(i1.lastIndexOf(">")+1, i1.length());

			//write output to stdout
			System.out.println(s1+s2+s3+s4+s5);
			System.out.println(i2.substring(0,i2.indexOf("."))+s4+s3+s2+s5);
		    }
		      
		} catch ( IOException e ) {
			e.printStackTrace( );
			System.exit( 1 );
		}
	} 


	
}
