#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 power(long long, long long);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, long long);
int strlen(char *);
int main(int argc, char *argv[]) {
  int cases;
  scanf("%d", &cases);
  int i;
  for (i = 0; i < cases; ++i) {
    long long a, b;
    scanf("%llu %llu", &a, &b);
    long long result = power(a, b);
    char str[1000000];
    sprintf(str, "%llu", result);
    char out = str[strlen(str) - 1];
    printf("%c\n", out);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120b <main+0xbb>
lea    0xe6e(%rip),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <power@plt>
mov    %rax,-0x30(%rbp)
lea    -0xf4270(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xf4270(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
mov    -0xf4270(%rbp,%rax,1),%al
mov    %al,-0xf4271(%rbp)
lea    0xe1c(%rip),%rdi
movsbl -0xf4271(%rbp),%esi
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <main+0x32>
xor    %eax,%eax
add    $0xf4280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf4268,%rsp
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11f3 <main+0xa3>
lea    0x18(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe7c(%rip),%r13
lea    0x20(%rsp),%rbx
lea    0xe75(%rip),%rbp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
lea    0xe5c(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1030 <power@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%esi
mov    %rbp,%rdi
call   1050 <printf@plt>
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
jl     11a0 <main+0x50>
xor    %eax,%eax
add    $0xf4268,%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"%llu %llu\00"
@.str.2 = [5 x i8] c"%llu\00"
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca [1000000 x i8]
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %7
br label %14
14: ; preds = %34, %2
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %8, i64* %9)
%20 = load i64, i64* %8
%21 = load i64, i64* %9
%22 = call i64 @power(i64 %20, i64 %21)
store i64 %22, i64* %10
%23 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 0
%24 = load i64, i64* %10
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 %29
%31 = load i8, i8* %30
store i8 %31, i8* %12
%32 = load i8, i8* %12
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %32)
br label %34
34: ; preds = %18
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %14
37: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%llu %llu\00"
@.str.2 = [5 x i8] c"%llu\00"
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca [1000000 x i8]
%7 = bitcast i32* %3 to i8*
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %2
%12 = bitcast i64* %4 to i8*
%13 = bitcast i64* %5 to i8*
%14 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %6, i64 0, i64 0
br label %15
15: ; preds = %11, %15
%16 = phi i32 [ 0, %11 ], [ %28, %15 ]
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %4, i64* %5)
%18 = load i64, i64* %4
%19 = load i64, i64* %5
%20 = call i64 @power(i64 %18, i64 %19)
%21 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %20)
%22 = call i32 @strlen(i8* %14)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %6, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %26)
%28 = add nuw nsw i32 %16, 1
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %15, label %31
31: ; preds = %15, %2
ret i32 0
}