#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*/ convert10tob(long long, long long);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, long long *, ...);
int main() {
  long long int n, b;
  long long int t, i, j, k;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &n, &b);
    if (n != 0) {
      convert10tob(n, b);
      printf("\n");
    } else
      printf("0\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebf(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     11ba <main+0x8a>
lea    0xe8f(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a9 <main+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <convert10tob@plt>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
jmp    11b5 <main+0x85>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
jmp    1151 <main+0x21>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb3(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subq   $0x1,(%rsp)
jb     11c4 <main+0x84>
lea    0xe96(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%rbx
lea    0xe8f(%rip),%r12
jmp    118f <main+0x4f>
nopl   (%rax)
mov    %r12,%rdi
call   1040 <puts@plt>
subq   $0x1,(%rsp)
jb     11c4 <main+0x84>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1180 <main+0x40>
mov    0x8(%rsp),%rsi
call   1050 <convert10tob@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
subq   $0x1,(%rsp)
jae    118f <main+0x4f>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [10 x i8] c"%lld %lld\00"
@str = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%8 = load i64, i64* %3
%9 = add nsw i64 %8, -1
store i64 %9, i64* %3
%10 = icmp eq i64 %8, 0
br i1 %10, label %25, label %11
11: ; preds = %0, %21
%12 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %1, i64* %2)
%13 = load i64, i64* %1
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i64, i64* %2
%17 = call i32 @convert10tob(i64 %13, i64 %16)
%18 = call i32 @putchar(i32 10)
br label %21
19: ; preds = %11
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i64, i64* %3
%23 = add nsw i64 %22, -1
store i64 %23, i64* %3
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %11
25: ; preds = %21, %0
ret i32 0
}