#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 */
long long gcd(long long, long long);
long long max(long long, long long);
long long min(long long, long long);
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int t;
  long long int s1, s2;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &s1, &s2);
    long long int ans = max(s1, s2) - min(s1, s2);
    if (ans < 0)
      ans *= -1;
    if (s1 < 0)
      s1 *= -1;
    if (s2 < 0)
      s2 *= -1;
    ans = ans / gcd(s1, s2);
    printf("%lld\n", ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     123d <main+0xed>
lea    0xe77(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <max@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <min@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11db <main+0x8b>
imul   $0xffffffffffffffff,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11ef <main+0x9f>
imul   $0xffffffffffffffff,-0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1203 <main+0xb3>
imul   $0xffffffffffffffff,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <gcd@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1030 <printf@plt>
jmp    1171 <main+0x21>
xor    %eax,%eax
add    $0x30,%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    0xe9b(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1189 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe73(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0xe6b(%rip),%r13
jmp    11ca <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rax
cqto
idiv   %rcx
mov    %rax,%rsi
mov    %r13,%rdi
call   1030 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1178 <main+0x28>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1050 <max@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1040 <min@plt>
sub    %rax,%rbp
mov    %rbp,%rbx
neg    %rbx
cmovs  %rbp,%rbx
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
jns    121a <main+0xca>
neg    %rdi
mov    %rdi,0x10(%rsp)
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
jns    122c <main+0xdc>
neg    %rsi
mov    %rsi,0x8(%rsp)
call   1070 <gcd@plt>
mov    %rax,%rcx
or     %rbx,%rax
shr    $0x20,%rax
jne    11b0 <main+0x60>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
jmp    11bb <main+0x6b>

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

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