public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		d: do {
			line = br.readLine();
			if (line == null || line.length() == 0)
				break d;
			int times = Integer.parseInt(line);
			String l1, l2;
			String[] w = new String[2];
			for (int i = 0; i < times; i++) {
				l1 = br.readLine();
				out.append(l1.replaceAll("<", "").replaceAll(">", "")).append(
						"\n");
				l2 = br.readLine();
				out.append(process(l1, l2)).append("\n");
			}
		} while (line != null && line.length() != 0);
		System.out.print(out);
	}