#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 *, unsigned long long);
int /*<<< orphan*/ scanf(char *, unsigned long long *, ...);
int main() {
  unsigned long long int n, i, a, b, swap, gcd;
  scanf("%llu", &n);
  for (i = 0; i < n; i++) {
    scanf("%llu %llu", &b, &a);
    while (1) {
      if (b == 0) {
        gcd = a;
        break;
      } else {
        swap = a;
        a = b;
        b = swap % b;
      }
    }
    printf("%llu\n", gcd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecf(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11cb <main+0xab>
lea    0xea2(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1185 <main+0x65>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11aa <main+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
mov    %rdx,-0x28(%rbp)
jmp    116d <main+0x4d>
mov    -0x38(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1149 <main+0x29>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpq   $0x0,0x18(%rsp)
je     11e2 <main+0xc2>
lea    0xead(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xea6(%rip),%r13
xor    %ebx,%ebx
jmp    1191 <main+0x71>
nopl   0x0(%rax,%rax,1)
mov    %rsi,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r13,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    0x18(%rsp),%rbx
jae    11e2 <main+0xc2>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
mov    %rsi,%rax
test   %rdx,%rdx
jne    11cd <main+0xad>
jmp    117e <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edx,%edx
div    %rsi
mov    %rsi,%rax
test   %rdx,%rdx
je     1170 <main+0x50>
mov    %rdx,%rsi
mov    %rax,%rcx
or     %rdx,%rcx
shr    $0x20,%rcx
jne    11c0 <main+0xa0>
xor    %edx,%edx
div    %esi
jmp    11c5 <main+0xa5>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [10 x i8] c"%llu %llu\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
store i64 0, i64* %3
br label %9
9: ; preds = %30, %0
%10 = load i64, i64* %3
%11 = load i64, i64* %2
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %5, i64* %4)
br label %15
15: ; preds = %13, %26
%16 = load i64, i64* %5
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i64, i64* %4
store i64 %19, i64* %7
br label %27
20: ; preds = %15
%21 = load i64, i64* %4
store i64 %21, i64* %6
%22 = load i64, i64* %5
store i64 %22, i64* %4
%23 = load i64, i64* %6
%24 = load i64, i64* %5
%25 = urem i64 %23, %24
store i64 %25, i64* %5
br label %26
26: ; preds = %20
br label %15
27: ; preds = %18
%28 = load i64, i64* %7
%29 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %28)
br label %30
30: ; preds = %27
%31 = load i64, i64* %3
%32 = add i64 %31, 1
store i64 %32, i64* %3
br label %9
33: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [10 x i8] c"%llu %llu\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%8 = load i64, i64* %1
%9 = icmp eq i64 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %0, %17
%11 = phi i64 [ %20, %17 ], [ 0, %0 ]
%12 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %3, i64* %2)
%13 = load i64, i64* %3
%14 = load i64, i64* %2
%15 = icmp eq i64 %13, 0
br i1 %15, label %17, label %23
16: ; preds = %23
store i64 %24, i64* %2
store i64 0, i64* %3
br label %17
17: ; preds = %16, %10
%18 = phi i64 [ %24, %16 ], [ %14, %10 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %18)
%20 = add nuw i64 %11, 1
%21 = load i64, i64* %1
%22 = icmp ult i64 %20, %21
br i1 %22, label %10, label %28
23: ; preds = %10, %23
%24 = phi i64 [ %26, %23 ], [ %13, %10 ]
%25 = phi i64 [ %24, %23 ], [ %14, %10 ]
%26 = urem i64 %25, %24
%27 = icmp eq i64 %26, 0
br i1 %27, label %16, label %23
28: ; preds = %17, %0
ret i32 0
}