#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 *, int, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int x, k, T, p, q;
  scanf("%d", &T);
  while (T) {
    scanf("%d %d", &x, &k);
    q = x % k;
    if (x >= k)
      p = (x - q) / (x / k) - q;
    else
      p = 0;
    printf("%d %d\n", p, q);
    T--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
je     11c1 <main+0xa1>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     119a <main+0x7a>
mov    -0x8(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
sub    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <main+0x81>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xece(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     11b7 <main+0x97>
lea    0xeb1(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xea6(%rip),%r13
jmp    1183 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ecx,%edx
call   1030 <printf@plt>
addl   $0xffffffff,0xc(%rsp)
je     11b7 <main+0x97>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%ebx
mov    %esi,%eax
cltd
idiv   %ebx
mov    %edx,%ecx
cmp    %ebx,%esi
jl     1170 <main+0x50>
mov    %eax,%edi
sub    %ecx,%esi
mov    %esi,%eax
cltd
idiv   %edi
mov    %eax,%ebp
sub    %ecx,%ebp
jmp    1170 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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