#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main() {
  int block, line, i, j, t;
  char c, input[50];
  freopen("input", "r", stdin);
  scanf("%d", &block);
  for (i = 0; i != block; ++i) {
    scanf("%d\n", &line);
    for (j = 0; j != line; ++j) {
      t = 0;
      while ((c = getchar()) != EOF) {
        if (c == ' ' || c == '\n') {
          while (t--)
            printf("%c", input[t]);
          printf("%c", c);
          if (c == '\n')
            break;
          t = 0;
        } else
          input[t++] = c;
      }
    }
    printf("\n");
    getchar();
  }
  fclose(stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    0xe91(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1050 <freopen@plt>
lea    0xe86(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     12b5 <main+0x165>
lea    0xe66(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1292 <main+0x142>
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e04(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     127f <main+0x12f>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
je     1201 <main+0xb1>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1266 <main+0x116>
jmp    1206 <main+0xb6>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1236 <main+0xe6>
movslq -0x18(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1206 <main+0xb6>
movsbl -0x19(%rbp),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    125a <main+0x10a>
jmp    127f <main+0x12f>
movl   $0x0,-0x18(%rbp)
jmp    127a <main+0x12a>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
cltq
mov    %cl,-0x50(%rbp,%rax,1)
jmp    11c8 <main+0x78>
jmp    1284 <main+0x134>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <main+0x65>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1192 <main+0x42>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
lea    0xe92(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1050 <freopen@plt>
lea    0xe87(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
je     1288 <main+0x138>
mov    0x2e43(%rip),%rbp
xor    %eax,%eax
jmp    11d2 <main+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0xc(%rsp),%eax
add    $0x1,%eax
cmp    0x8(%rsp),%eax
je     1288 <main+0x138>
mov    %eax,0xc(%rsp)
lea    0xe2e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
je     11b0 <main+0x60>
xor    %r14d,%r14d
jmp    120b <main+0xbb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
je     11b0 <main+0x60>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    0x0(%rbp),%al
je     1200 <main+0xb0>
mov    %eax,%ebx
xor    %r15d,%r15d
jmp    1239 <main+0xe9>
xchg   %ax,%ax
movslq %r15d,%rax
add    $0x1,%r15d
mov    %bl,0x10(%rsp,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
cmp    0x0(%rbp),%al
je     1200 <main+0xb0>
cmp    $0x20,%bl
je     1243 <main+0xf3>
cmp    $0xa,%bl
jne    1220 <main+0xd0>
test   %r15d,%r15d
je     1273 <main+0x123>
movslq %r15d,%r12
lea    0xf(%rsp),%rax
add    %rax,%r12
neg    %r15d
xor    %r13d,%r13d
nopl   0x0(%rax)
movsbl (%r12,%r13,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%r13
cmp    %r13d,%r15d
jne    1260 <main+0x110>
movsbl %bl,%edi
call   1030 <putchar@plt>
xor    %r15d,%r15d
cmp    $0xa,%bl
jne    122b <main+0xdb>
jmp    1200 <main+0xb0>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@EOF = global i8 0
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca [50 x i8]
store i32 0, i32* %1
%9 = load i32, i32* @stdin
%10 = call i32 @freopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
store i32 0, i32* %4
br label %12
12: ; preds = %72, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %75
16: ; preds = %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
store i32 0, i32* %5
br label %18
18: ; preds = %66, %16
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %69
22: ; preds = %18
store i32 0, i32* %6
br label %23
23: ; preds = %64, %22
%24 = call signext i8 (...) @getchar()
store i8 %24, i8* %7
%25 = sext i8 %24 to i32
%26 = load i8, i8* @EOF
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %65
29: ; preds = %23
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 32
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8, i8* %7
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %58
37: ; preds = %33, %29
br label %38
38: ; preds = %42, %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, -1
store i32 %40, i32* %6
%41 = icmp ne i32 %39, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %38
49: ; preds = %38
%50 = load i8, i8* %7
%51 = sext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = load i8, i8* %7
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %57
56: ; preds = %49
br label %65
57: ; preds = %49
store i32 0, i32* %6
br label %64
58: ; preds = %33
%59 = load i8, i8* %7
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 %62
store i8 %59, i8* %63
br label %64
64: ; preds = %58, %57
br label %23
65: ; preds = %56, %23
br label %66
66: ; preds = %65
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
br label %18
69: ; preds = %18
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%71 = call signext i8 (...) @getchar()
br label %72
72: ; preds = %69
%73 = load i32, i32* %4
%74 = add nsw i32 %73, 1
store i32 %74, i32* %4
br label %12
75: ; preds = %12
%76 = load i32, i32* @stdin
%77 = call i32 @fclose(i32 %76)
ret i32 0
}

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