#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ scanf(char *, int *);
char *strchr(char *, char);
int strlen(char *);
int main() {
  char line1[128], line2[128];
  char *s1, *s2, *s3, *s4, *s5;
  char *ptr;
  int num_cases;
  scanf("%d\n", &num_cases);
  while (num_cases-- > 0) {
    gets(&line1[0]);
    gets(&line2[0]);
    s1 = &line1[0];
    ptr = strchr(s1, '<');
    *ptr = '\0';
    s2 = ++ptr;
    ptr = strchr(s2, '>');
    *ptr = '\0';
    s3 = ++ptr;
    ptr = strchr(s3, '<');
    *ptr = '\0';
    s4 = ++ptr;
    ptr = strchr(s4, '>');
    *ptr = '\0';
    s5 = ++ptr;
    ptr = &line2[0];
    ptr = ptr + strlen(line2) - 3;
    *ptr = '\0';
    printf("%s%s%s%s%s\n", s1, s2, s3, s4, s5);
    printf("%s%s%s%s%s\n", line2, s4, s3, s2, s5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    -0x144(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x144(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x144(%rbp)
cmp    $0x0,%eax
jle    1350 <main+0x200>
lea    -0x90(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x110(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
mov    $0x3c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
mov    $0x3e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    $0x3c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rdi
mov    $0x3e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
mov    %rax,-0x138(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x150(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xfffffffffffffffd,%rax
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x118(%rbp),%rsi
mov    -0x120(%rbp),%rdx
mov    -0x128(%rbp),%rcx
mov    -0x130(%rbp),%r8
mov    -0x138(%rbp),%r9
lea    0xced(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
mov    -0x130(%rbp),%rdx
mov    -0x128(%rbp),%rcx
mov    -0x120(%rbp),%r8
mov    -0x138(%rbp),%r9
lea    0xcbe(%rip),%rdi
call   1050 <printf@plt>
jmp    1175 <main+0x25>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    124b <main+0xfb>
lea    0x90(%rsp),%r12
mov    %r12,%rdi
call   1060 <gets@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <gets@plt>
mov    %r12,%rdi
mov    $0x3c,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%r13
mov    %r13,%rdi
mov    $0x3e,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%rbx
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%rbp
mov    %rbp,%rdi
mov    $0x3e,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,0xd(%rsp,%rax,1)
lea    0xdee(%rip),%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
mov    %r15,%r9
call   1050 <printf@plt>
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
mov    %r15,%r9
call   1050 <printf@plt>
jmp    1180 <main+0x30>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [12 x i8] c"%s%s%s%s%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %10)
br label %12
12: ; preds = %16, %0
%13 = load i32, i32* %10
%14 = add nsw i32 %13, -1
store i32 %14, i32* %10
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %62
16: ; preds = %12
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%18 = call i32 @gets(i8* %17)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = call i32 @gets(i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = call i8* @strchr(i8* %22, i8 signext 60)
store i8* %23, i8** %9
%24 = load i8*, i8** %9
store i8 0, i8* %24
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %9
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = call i8* @strchr(i8* %27, i8 signext 62)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
store i8 0, i8* %29
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %9
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = call i8* @strchr(i8* %32, i8 signext 60)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
store i8 0, i8* %34
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %9
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = call i8* @strchr(i8* %37, i8 signext 62)
store i8* %38, i8** %9
%39 = load i8*, i8** %9
store i8 0, i8* %39
%40 = load i8*, i8** %9
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %9
store i8* %41, i8** %8
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8* %42, i8** %9
%43 = load i8*, i8** %9
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = getelementptr inbounds i8, i8* %47, i64 -3
store i8* %48, i8** %9
%49 = load i8*, i8** %9
store i8 0, i8* %49
%50 = load i8*, i8** %4
%51 = load i8*, i8** %5
%52 = load i8*, i8** %6
%53 = load i8*, i8** %7
%54 = load i8*, i8** %8
%55 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %51, i8* %52, i8* %53, i8* %54)
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%57 = load i8*, i8** %7
%58 = load i8*, i8** %6
%59 = load i8*, i8** %5
%60 = load i8*, i8** %8
%61 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %56, i8* %57, i8* %58, i8* %59, i8* %60)
br label %12
62: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [12 x i8] c"%s%s%s%s%s\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %31
11: ; preds = %0, %11
%12 = call i32 @gets(i8* %4)
%13 = call i32 @gets(i8* %5)
%14 = call i8* @strchr(i8* %4, i8 signext 60)
store i8 0, i8* %14
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i8* @strchr(i8* %15, i8 signext 62)
store i8 0, i8* %16
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = call i8* @strchr(i8* %17, i8 signext 60)
store i8 0, i8* %18
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i8* @strchr(i8* %19, i8 signext 62)
store i8 0, i8* %20
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @strlen(i8* %5)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -3
store i8 0, i8* %25
%26 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %15, i8* %17, i8* %19, i8* %21)
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %19, i8* %17, i8* %15, i8* %21)
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
%30 = icmp sgt i32 %28, 0
br i1 %30, label %11, label %31
31: ; preds = %11, %0
ret i32 0
}