#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int t;
  scanf("%d", &t);
  long long int k, n, m, h, p;
  while (t--) {
    scanf("%lld %lld", &n, &m);
    if (m == 0) {
      if (n != 1)
        printf("No 1\n");
      else
        printf("Yes\n");
    } else {
      h = gcd(n, m);
      p = m / h;
      k = (p * n) / m;
      if (k < n)
        printf("No %lld\n", k);
      else
        printf("Yes\n");
    }
  }
  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     1226 <main+0xf6>
lea    0xe97(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <main+0x87>
cmpq   $0x1,-0x18(%rbp)
je     11a4 <main+0x74>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <main+0x82>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <main+0xf1>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <gcd@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
imul   -0x18(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    120e <main+0xde>
mov    -0x10(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121c <main+0xec>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <main+0xf1>
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    0xeab(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jb     1260 <main+0x120>
lea    0xe90(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%rbx
lea    0xe92(%rip),%r12
lea    0xe8f(%rip),%r13
lea    0xe7b(%rip),%rbp
jmp    11b8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1260 <main+0x120>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdi
test   %rsi,%rsi
je     1200 <main+0xc0>
call   1060 <gcd@plt>
mov    %rax,%rsi
mov    0x8(%rsp),%rcx
or     %rcx,%rax
shr    $0x20,%rax
je     1210 <main+0xd0>
mov    %rcx,%rax
cqto
idiv   %rsi
jmp    1216 <main+0xd6>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%rdi
je     124d <main+0x10d>
mov    %r13,%rdi
jmp    1250 <main+0x110>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    0x10(%rsp),%rsi
imul   %rsi,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1240 <main+0x100>
cqto
idiv   %rcx
cmp    %rsi,%rax
jl     11a0 <main+0x60>
jmp    124d <main+0x10d>
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %ecx
cmp    %rsi,%rax
jl     11a0 <main+0x60>
mov    %r12,%rdi
call   1030 <puts@plt>
subl   $0x1,0x4(%rsp)
jae    11b8 <main+0x78>
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"No 1\0A\00"
@.str.3 = [5 x i8] c"Yes\0A\00"
@.str.4 = [9 x i8] c"No %lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %46, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %47
13: ; preds = %9
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %4, i64* %5)
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i64, i64* %4
%19 = icmp ne i64 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
br label %46
25: ; preds = %13
%26 = load i64, i64* %4
%27 = load i64, i64* %5
%28 = call i64 @gcd(i64 %26, i64 %27)
store i64 %28, i64* %6
%29 = load i64, i64* %5
%30 = load i64, i64* %6
%31 = sdiv i64 %29, %30
store i64 %31, i64* %7
%32 = load i64, i64* %7
%33 = load i64, i64* %4
%34 = mul nsw i64 %32, %33
%35 = load i64, i64* %5
%36 = sdiv i64 %34, %35
store i64 %36, i64* %3
%37 = load i64, i64* %3
%38 = load i64, i64* %4
%39 = icmp slt i64 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %25
%41 = load i64, i64* %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64 %41)
br label %45
43: ; preds = %25
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
br label %46
46: ; preds = %45, %24
br label %9
47: ; preds = %9
ret i32 0
}

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