#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 /*<<< orphan*/ scanf(char *, int *, ...);
scalar_t__ sqrt(int);
int main() {
  int n, x, y, gap;
  int step, max;
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    gap = y - x;
    step = 0;
    if (gap == 0) {
      printf("0\n");
      continue;
    }
    max = (int)sqrt(gap);
    gap = gap - max * max;
    step += (2 * max - 1);
    while (gap != 0) {
      while (gap - max < 0)
        max--;
      step += 1;
      gap -= max;
    }
    printf("%d\n", step);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1234 <main+0x104>
lea    0xe95(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a7 <main+0x77>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1226 <main+0xf6>
mov    -0x14(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1215 <main+0xe5>
jmp    11df <main+0xaf>
mov    -0x14(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x0,%eax
jge    11fc <main+0xcc>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11df <main+0xaf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <main+0xa0>
mov    -0x18(%rbp),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1158 <main+0x28>
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    0xeae(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1207 <main+0xc7>
lea    0xe8d(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%rbx
lea    0xe82(%rip),%r13
xor    %r12d,%r12d
jmp    11a7 <main+0x67>
nopl   0x0(%rax)
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r12d
cmp    0xc(%rsp),%r12d
jge    1207 <main+0xc7>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%ebp
sub    0x14(%rsp),%ebp
je     1190 <main+0x50>
mov    %ebp,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
imul   %eax,%ecx
lea    (%rax,%rax,1),%esi
add    $0xffffffff,%esi
sub    %ecx,%ebp
je     11fb <main+0xbb>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%ecx
sub    %eax,%ecx
test   %ecx,%ecx
mov    $0x0,%edx
cmovg  %ecx,%edx
sub    %edx,%ebp
add    $0x1,%esi
mov    %ebp,%eax
mov    %edx,%ebp
test   %ecx,%ecx
jg     11e0 <main+0xa0>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <main+0x5c>
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 = [3 x i8] c"0\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %8
br label %10
10: ; preds = %58, %0
%11 = load i32, i32* %8
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %61
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = sub nsw i32 %16, %17
store i32 %18, i32* %5
store i32 0, i32* %6
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %58
23: ; preds = %14
%24 = load i32, i32* %5
%25 = call i64 @sqrt(i32 %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i32, i32* %5
%28 = load i32, i32* %7
%29 = load i32, i32* %7
%30 = mul nsw i32 %28, %29
%31 = sub nsw i32 %27, %30
store i32 %31, i32* %5
%32 = load i32, i32* %7
%33 = mul nsw i32 2, %32
%34 = sub nsw i32 %33, 1
%35 = load i32, i32* %6
%36 = add nsw i32 %35, %34
store i32 %36, i32* %6
br label %37
37: ; preds = %49, %23
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %37
br label %41
41: ; preds = %46, %40
%42 = load i32, i32* %5
%43 = load i32, i32* %7
%44 = sub nsw i32 %42, %43
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %7
%48 = add nsw i32 %47, -1
store i32 %48, i32* %7
br label %41
49: ; preds = %41
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
%52 = load i32, i32* %7
%53 = load i32, i32* %5
%54 = sub nsw i32 %53, %52
store i32 %54, i32* %5
br label %37
55: ; preds = %37
%56 = load i32, i32* %6
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %21
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %10
61: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [2 x i8] c"0\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* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %43
10: ; preds = %0, %39
%11 = phi i32 [ %40, %39 ], [ 0, %0 ]
%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* %3
%14 = load i32, i32* %2
%15 = sub nsw i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %39
19: ; preds = %10
%20 = call i64 @sqrt(i32 %15)
%21 = trunc i64 %20 to i32
%22 = mul nsw i32 %21, %21
%23 = sub nsw i32 %15, %22
%24 = shl nsw i32 %21, 1
%25 = add nsw i32 %24, -1
%26 = icmp eq i32 %23, 0
br i1 %26, label %36, label %27
27: ; preds = %19, %27
%28 = phi i32 [ %33, %27 ], [ %21, %19 ]
%29 = phi i32 [ %34, %27 ], [ %25, %19 ]
%30 = phi i32 [ %32, %27 ], [ %23, %19 ]
%31 = sub i32 %30, %28
%32 = call i32 @llvm.smax.i32(i32 %31, i32 0)
%33 = sub i32 %30, %32
%34 = add nsw i32 %29, 1
%35 = icmp slt i32 %31, 1
br i1 %35, label %36, label %27
36: ; preds = %27, %19
%37 = phi i32 [ %25, %19 ], [ %34, %27 ]
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %17
%40 = add nuw nsw i32 %11, 1
%41 = load i32, i32* %1
%42 = icmp slt i32 %40, %41
br i1 %42, label %10, label %43
43: ; preds = %39, %0
ret i32 0
}