1. JAVA, Till Fischer

/*

 ============================================================================

 Name            : 10361 - Automatic Poetry

 Author            : Till Fischer

 Accepted        : yes

 Time            : 0.090

 ============================================================================

 */



import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;



public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        String s2,s3,s4,s5,lineOne,lineTwo;

        int beginFirst,endFirst,beginSecond,endSecond;

       

        int cases = Integer.parseInt(reader.readLine());

       

        for(int i = 0; i < cases; i++) {

            lineOne = reader.readLine();

            lineTwo = reader.readLine();

           

           

            beginFirst = lineOne.indexOf("<");

            endFirst = lineOne.indexOf(">");

            beginSecond = lineOne.lastIndexOf("<");

            endSecond = lineOne.lastIndexOf(">");

           

           

            s2 = lineOne.substring(beginFirst + 1, endFirst);

            s3 = lineOne.substring(endFirst + 1, beginSecond);

            s4 = lineOne.substring(beginSecond + 1, endSecond);

            s5 = lineOne.substring(endSecond + 1);

           

            lineTwo = lineTwo.replace("...", "");

            lineTwo += s4 + s3 + s2 + s5;

            lineOne = lineOne.replace(">", "").replace("<", "");

            writer.write(lineOne + "\n");

            writer.write(lineTwo + "\n");

           

        }

        reader.close();

        writer.flush();

        writer.close();

    }

}