#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 gcd(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int num, a, b, c, d, var;
  scanf("%d", &num);
  for (int i = 0; i < num; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (b == 0 || d == 0)
      printf("Not A Number\n");
    else if (a == 0 || c == 0)
      printf("0\n");
    else {
      var = gcd(a * c, b * d);
      if (var == b * d)
        printf("%d\n", a * c / var);
      else
        printf("%d/%d\n", a * c / var, b * d / var);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec0(%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    125d <main+0x12d>
lea    0xe95(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
je     1196 <main+0x66>
cmpl   $0x0,-0x18(%rbp)
jne    11a9 <main+0x79>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124a <main+0x11a>
cmpl   $0x0,-0xc(%rbp)
je     11bd <main+0x8d>
cmpl   $0x0,-0x14(%rbp)
jne    11d0 <main+0xa0>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <main+0x115>
mov    -0xc(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
imul   -0x18(%rbp),%esi
call   1050 <gcd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jne    1218 <main+0xe8>
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x110>
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%eax
imul   -0x18(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%edx
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <main+0x115>
jmp    124a <main+0x11a>
jmp    124f <main+0x11f>
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    0xeb1(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x14(%rsp)
jle    1246 <main+0x106>
lea    0xe8d(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%rbx
xor    %ebp,%ebp
jmp    11a9 <main+0x69>
nopl   0x0(%rax,%rax,1)
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    0x14(%rsp),%ebp
jge    1246 <main+0x106>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1190 <main+0x50>
mov    0x4(%rsp),%esi
test   %esi,%esi
je     1190 <main+0x50>
mov    0x10(%rsp),%ecx
test   %ecx,%ecx
je     1220 <main+0xe0>
mov    0x8(%rsp),%edi
test   %edi,%edi
je     1220 <main+0xe0>
imul   %ecx,%edi
imul   %eax,%esi
call   1060 <gcd@plt>
mov    0x4(%rsp),%ecx
imul   0xc(%rsp),%ecx
mov    0x8(%rsp),%edx
imul   0x10(%rsp),%edx
mov    %eax,%edi
mov    %edx,%eax
cltd
idiv   %edi
mov    %eax,%esi
cmp    %ecx,%edi
jne    122c <main+0xec>
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <main+0x5c>
nopl   0x0(%rax)
lea    0xde9(%rip),%rdi
jmp    1197 <main+0x57>
mov    %ecx,%eax
cltd
idiv   %edi
lea    0xdd1(%rip),%rdi
mov    %eax,%edx
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 = [9 x i8] c"%d%d%d%d\00"
@.str.2 = [14 x i8] c"Not A Number\0A\00"
@.str.3 = [3 x i8] c"0\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [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
%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 = %66, %0
%11 = load i32, i32* %8
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %69
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18, %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %65
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26, %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %64
31: ; preds = %26
%32 = load i32, i32* %3
%33 = load i32, i32* %5
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %4
%36 = load i32, i32* %6
%37 = mul nsw i32 %35, %36
%38 = call i32 @gcd(i32 %34, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = load i32, i32* %4
%41 = load i32, i32* %6
%42 = mul nsw i32 %40, %41
%43 = icmp eq i32 %39, %42
br i1 %43, label %44, label %51
44: ; preds = %31
%45 = load i32, i32* %3
%46 = load i32, i32* %5
%47 = mul nsw i32 %45, %46
%48 = load i32, i32* %7
%49 = sdiv i32 %47, %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %63
51: ; preds = %31
%52 = load i32, i32* %3
%53 = load i32, i32* %5
%54 = mul nsw i32 %52, %53
%55 = load i32, i32* %7
%56 = sdiv i32 %54, %55
%57 = load i32, i32* %4
%58 = load i32, i32* %6
%59 = mul nsw i32 %57, %58
%60 = load i32, i32* %7
%61 = sdiv i32 %59, %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %56, i32 %61)
br label %63
63: ; preds = %51, %44
br label %64
64: ; preds = %63, %29
br label %65
65: ; preds = %64, %21
br label %66
66: ; preds = %65
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %10
69: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d%d%d%d\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [7 x i8] c"%d/%d\0A\00"
@str = [2 x i8] c"0\00"
@str.6 = [13 x i8] c"Not A Number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %50, %0
ret i32 0
15: ; preds = %0, %50
%16 = phi i32 [ %51, %50 ], [ 0, %0 ]
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 0
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %50
25: ; preds = %15
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 0
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %50
33: ; preds = %25
%34 = mul nsw i32 %28, %26
%35 = mul nsw i32 %20, %18
%36 = call i32 @gcd(i32 %34, i32 %35)
%37 = load i32, i32* %3
%38 = load i32, i32* %5
%39 = mul nsw i32 %38, %37
%40 = icmp eq i32 %36, %39
%41 = load i32, i32* %2
%42 = load i32, i32* %4
%43 = mul nsw i32 %42, %41
%44 = sdiv i32 %43, %36
br i1 %40, label %45, label %47
45: ; preds = %33
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %50
47: ; preds = %33
%48 = sdiv i32 %39, %36
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %48)
br label %50
50: ; preds = %23, %45, %47, %31
%51 = add nuw nsw i32 %16, 1
%52 = load i32, i32* %1
%53 = icmp slt i32 %51, %52
br i1 %53, label %15, label %14
}