#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 sqrt(long long);
int main() {
  int t;
  long long a, b, a1, b1;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld %lld", &a, &b);
    a1 = sqrt(a);
    if (a1 * a1 == a)
      a1--;
    b1 = sqrt(b);
    printf("%lld\n", (b1 - a1));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11cd <main+0x9d>
lea    0xe97(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11a7 <main+0x77>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
jmp    1151 <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    0xebb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x4(%rsp)
jb     11be <main+0x8e>
lea    0xea4(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe9d(%rip),%r13
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rdi
call   1050 <sqrt@plt>
mov    %rax,%rbx
imul   %rax,%rax
xor    %ebp,%ebp
cmp    0x8(%rsp),%rax
sete   %bpl
mov    0x10(%rsp),%rdi
call   1050 <sqrt@plt>
sub    %rbx,%rbp
add    %rax,%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
subl   $0x1,0x4(%rsp)
jae    1170 <main+0x40>
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 = [10 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
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %24, %0
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %3, i64* %4)
%14 = load i64, i64* %3
%15 = call i64 @sqrt(i64 %14)
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = load i64, i64* %5
%18 = mul nsw i64 %16, %17
%19 = load i64, i64* %3
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i64, i64* %5
%23 = add nsw i64 %22, -1
store i64 %23, i64* %5
br label %24
24: ; preds = %21, %12
%25 = load i64, i64* %4
%26 = call i64 @sqrt(i64 %25)
store i64 %26, i64* %6
%27 = load i64, i64* %6
%28 = load i64, i64* %5
%29 = sub nsw i64 %27, %28
%30 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %29)
br label %8
31: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 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 %27, label %11
11: ; preds = %0, %11
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3)
%13 = load i64, i64* %2
%14 = call i64 @sqrt(i64 %13)
%15 = mul nsw i64 %14, %14
%16 = load i64, i64* %2
%17 = icmp eq i64 %15, %16
%18 = zext i1 %17 to i64
%19 = load i64, i64* %3
%20 = call i64 @sqrt(i64 %19)
%21 = sub i64 %18, %14
%22 = add i64 %21, %20
%23 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %22)
%24 = load i32, i32* %1
%25 = add nsw i32 %24, -1
store i32 %25, i32* %1
%26 = icmp eq i32 %24, 0
br i1 %26, label %27, label %11
27: ; preds = %11, %0
ret i32 0
}