1. 

/* @Problem 10361 Automatic Poetry

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1302

* @Autor Markus Stadler
* @Autor Johannes Müller

Runtime: 0.084
*/

import java.io.*;
import java.util.ArrayList;

class AutomaticPoetry {
public static void main (String[] args) throws Exception {
BufferedReader buin = new BufferedReader (new InputStreamReader (System.in));
Writer out = new BufferedWriter(new PrintWriter(System.out));
int reime = Integer.parseInt(buin.readLine()); //anzahl der reime
for (int r = 0; r < reime; r++){
String line = buin.readLine().replace('>', '<'); //erste zeile wird in 5 teile aufgeteilt
String[] parttmp = new String[5];
String[] parts = new String[5];
parttmp = line.split("<"); //erstellt neues array
for(int i = 0; i < 5; i++){
try{
parts[i] = parttmp[i];
}
catch(Exception ex){
parts[i] = "";
}
}
for(int i = 0; i < 5; i++){
out.write(parts[i]);
}
out.write("\n");
line = buin.readLine();
int dotrem = line.length();
line = line.substring(0, (dotrem - 3)); //erste zeile wird ausgegeben
if(line != null) //zweite zeile wird ausgegeben
out.write(line);
out.write(parts[3]);
out.write(parts[2]);
out.write(parts[1]);
out.write(parts[4]);
out.write("\n");
}
out.close();
buin.close();
}
}