#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*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, long long *);
int main(void) {
  long long int t, k;
  scanf("%lld", &t);
  while (t--) {
    long long int r, s = 0, c = 1;
    scanf("%lld", &k);
    k = k - 1;
    while (k > 0) {
      r = k % 5;
      s = r * c + s;
      c = c * 10;
      k = k / 5;
    }
    s = s * 2;
    printf("%lld\n", s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     11f3 <main+0xd3>
movq   $0x0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
lea    0xe91(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11d2 <main+0xb2>
mov    -0x18(%rbp),%rax
mov    $0x5,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
imul   $0xa,-0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x5,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
jmp    1184 <main+0x64>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0x1f>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecc(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
subq   $0x1,0x8(%rsp)
jae    1156 <main+0x36>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xea3(%rip),%r14
mov    %rsp,%r15
movabs $0xcccccccccccccccd,%r13
cc cc cc
lea    0xe94(%rip),%r12
jmp    1199 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %esi,%esi
mov    %rbx,(%rsp)
add    %rsi,%rsi
mov    %r12,%rdi
call   1030 <printf@plt>
subq   $0x1,0x8(%rsp)
jb     1146 <main+0x26>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%rax
lea    -0x1(%rax),%rbx
cmp    $0x2,%rax
jl     1180 <main+0x60>
mov    $0x1,%edi
xor    %esi,%esi
nopl   0x0(%rax)
mov    %rbx,%rax
mul    %r13
shr    $0x2,%rdx
lea    (%rdx,%rdx,4),%rax
mov    %rbx,%rcx
sub    %rax,%rcx
imul   %rdi,%rcx
add    %rcx,%rsi
add    %rdi,%rdi
lea    (%rdi,%rdi,4),%rdi
cmp    $0x4,%rbx
mov    %rdx,%rbx
ja     11c0 <main+0xa0>
xor    %ebx,%ebx
jmp    1182 <main+0x62>

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
br label %8
8: ; preds = %31, %0
%9 = load i64, i64* %2
%10 = add nsw i64 %9, -1
store i64 %10, i64* %2
%11 = icmp ne i64 %9, 0
br i1 %11, label %12, label %36
12: ; preds = %8
store i64 0, i64* %5
store i64 1, i64* %6
%13 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%14 = load i64, i64* %3
%15 = sub nsw i64 %14, 1
store i64 %15, i64* %3
br label %16
16: ; preds = %19, %12
%17 = load i64, i64* %3
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i64, i64* %3
%21 = srem i64 %20, 5
store i64 %21, i64* %4
%22 = load i64, i64* %4
%23 = load i64, i64* %6
%24 = mul nsw i64 %22, %23
%25 = load i64, i64* %5
%26 = add nsw i64 %24, %25
store i64 %26, i64* %5
%27 = load i64, i64* %6
%28 = mul nsw i64 %27, 10
store i64 %28, i64* %6
%29 = load i64, i64* %3
%30 = sdiv i64 %29, 5
store i64 %30, i64* %3
br label %16
31: ; preds = %16
%32 = load i64, i64* %5
%33 = mul nsw i64 %32, 2
store i64 %33, i64* %5
%34 = load i64, i64* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %34)
br label %8
36: ; preds = %8
ret i32 0
}

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