#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 division(char *, int);
int /*<<< orphan*/ fast_exp(long long, long long, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char n[100001], m[100001];
  long long int d, p, v;
  int t;
  scanf("%lld", &t);
  while (t--) {
    scanf("%s", n);
    scanf("%s", m);
    d = division(n, 1000000007);
    p = division(m, 1000000007 - 1);
    printf("%lld\n", fast_exp(d, p, 1000000007));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x30d7c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x30d7c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x30d7c(%rbp)
cmp    $0x0,%eax
je     1206 <main+0xc6>
lea    -0x186b0(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x30d60(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x186b0(%rbp),%rdi
mov    $0x3b9aca07,%esi
call   1040 <division@plt>
mov    %rax,-0x30d68(%rbp)
lea    -0x30d60(%rbp),%rdi
mov    $0x3b9aca06,%esi
call   1040 <division@plt>
mov    %rax,-0x30d70(%rbp)
mov    -0x30d68(%rbp),%rdi
mov    -0x30d70(%rbp),%rsi
mov    $0x3b9aca07,%edx
call   1060 <fast_exp@plt>
mov    %eax,%esi
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
jmp    1167 <main+0x27>
xor    %eax,%eax
add    $0x30d80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30d70,%rsp
lea    0xea9(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0xc(%rsp)
jb     11e8 <main+0xa8>
lea    0xe94(%rip),%r14
lea    0x186c0(%rsp),%r15
lea    0x10(%rsp),%r13
lea    0xe83(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15,%rdi
mov    $0x3b9aca07,%esi
call   1040 <division@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x3b9aca06,%esi
call   1040 <division@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x3b9aca07,%edx
call   1060 <fast_exp@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jae    1190 <main+0x50>
xor    %eax,%eax
add    $0x30d70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100001 x i8]
%3 = alloca [100001 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %7)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %7
%11 = add nsw i32 %10, -1
store i32 %11, i32* %7
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = getelementptr inbounds [100001 x i8], [100001 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [100001 x i8], [100001 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [100001 x i8], [100001 x i8]* %2, i64 0, i64 0
%19 = call i64 @division(i8* %18, i32 1000000007)
store i64 %19, i64* %4
%20 = getelementptr inbounds [100001 x i8], [100001 x i8]* %3, i64 0, i64 0
%21 = call i64 @division(i8* %20, i32 1000000006)
store i64 %21, i64* %5
%22 = load i64, i64* %4
%23 = load i64, i64* %5
%24 = call i32 @fast_exp(i64 %22, i64 %23, i32 1000000007)
%25 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %9
26: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca [100001 x i8]
%2 = alloca [100001 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [100001 x i8], [100001 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100001 x i8], [100001 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = icmp eq i32 %8, 0
br i1 %10, label %21, label %11
11: ; preds = %0, %11
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%14 = call i64 @division(i8* %4, i32 1000000007)
%15 = call i64 @division(i8* %5, i32 1000000006)
%16 = call i32 @fast_exp(i64 %14, i64 %15, i32 1000000007)
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
%20 = icmp eq i32 %18, 0
br i1 %20, label %21, label %11
21: ; preds = %11, %0
ret i32 0
}