#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 */
typedef int /*<<< orphan*/ table;
typedef int /*<<< orphan*/ keyword;
typedef int /*<<< orphan*/ ciphertext;

/* Variables and functions */
int /*<<< orphan*/ buildTable(char *, char *);
int decryptChar(char, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ removeDuplicates(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sortTable(char *, char *, int);
int strlen(char *);
int main() {
  int i, j, N;
  char keyword[8], ciphertext[256], table[27];
  scanf("%d", &N);
  getchar();
  for (i = 0; i < N; i++) {
    memset(keyword, 0, sizeof(keyword));
    memset(ciphertext, 0, sizeof(ciphertext));
    memset(table, 0, sizeof(table));
    gets(keyword);
    gets(ciphertext);
    removeDuplicates(keyword);
    buildTable(keyword, table);
    sortTable(keyword, table, strlen(keyword));
    for (j = 0; j < strlen(ciphertext); j++) {
      if (ciphertext[j] == ' ') {
        printf(" ");
        continue;
      }
      printf("%c", decryptChar(ciphertext[j], table));
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <scanf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    131f <main+0x17f>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
lea    -0x18(%rbp),%rdi
call   10a0 <gets@plt>
lea    -0x120(%rbp),%rdi
call   10a0 <gets@plt>
lea    -0x18(%rbp),%rdi
call   1070 <removeDuplicates@plt>
lea    -0x18(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   1090 <buildTable@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    %eax,%edx
call   10c0 <sortTable@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x154(%rbp)
lea    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x154(%rbp),%eax
cmp    %ecx,%eax
jge    1303 <main+0x163>
movslq -0xc(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    12cb <main+0x12b>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f5 <main+0x155>
movslq -0xc(%rbp),%rax
mov    -0x120(%rbp,%rax,1),%al
lea    -0x140(%rbp),%rsi
movsbl %al,%edi
call   1060 <decryptChar@plt>
mov    %eax,%esi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    127e <main+0xde>
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d0 <main+0x30>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x130,%rsp
lea    0xe49(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
xor    %r12d,%r12d
xor    %eax,%eax
call   1080 <getchar@plt>
cmpl   $0x0,0x4(%rsp)
jle    12c9 <main+0x129>
lea    0x8(%rsp),%r14
lea    0x30(%rsp),%r13
lea    0x10(%rsp),%r15
jmp    1209 <main+0x69>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
cmp    0x4(%rsp),%r12d
jge    12c9 <main+0x129>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
call   10a0 <gets@plt>
mov    %r13,%rdi
call   10a0 <gets@plt>
mov    %r14,%rdi
call   1070 <removeDuplicates@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <buildTable@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   10c0 <sortTable@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11f0 <main+0x50>
xor    %ebx,%ebx
jmp    12ac <main+0x10c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11f0 <main+0x50>
movzbl 0x30(%rsp,%rbx,1),%eax
mov    $0x20,%edi
cmp    $0x20,%al
je     1290 <main+0xf0>
movsbl %al,%edi
mov    %r15,%rsi
call   1060 <decryptChar@plt>
mov    %eax,%edi
jmp    1290 <main+0xf0>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [256 x i8]
%4 = alloca [27 x i8]
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = call i32 (...) @getchar()
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %45
13: ; preds = %0, %40
%14 = phi i32 [ %42, %40 ], [ 0, %0 ]
%15 = call i32 @memset(i8* %6, i32 0, i32 8)
%16 = call i32 @memset(i8* %7, i32 0, i32 256)
%17 = call i32 @memset(i8* %8, i32 0, i32 27)
%18 = call i32 @gets(i8* %6)
%19 = call i32 @gets(i8* %7)
%20 = call i32 @removeDuplicates(i8* %6)
%21 = call i32 @buildTable(i8* %6, i8* %8)
%22 = call i32 @strlen(i8* %6)
%23 = call i32 @sortTable(i8* %6, i8* %8, i32 %22)
%24 = call i32 @strlen(i8* %7)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %13, %33
%27 = phi i64 [ %36, %33 ], [ 0, %13 ]
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 32
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = call i32 @decryptChar(i8 signext %29, i8* %8)
br label %33
33: ; preds = %26, %31
%34 = phi i32 [ %32, %31 ], [ 32, %26 ]
%35 = call i32 @putchar(i32 %34)
%36 = add nuw nsw i64 %27, 1
%37 = call i32 @strlen(i8* %7)
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %26, label %40
40: ; preds = %33, %13
%41 = call i32 @putchar(i32 10)
%42 = add nuw nsw i32 %14, 1
%43 = load i32, i32* %1
%44 = icmp slt i32 %42, %43
br i1 %44, label %13, label %45
45: ; preds = %40, %0
ret i32 0
}