import java.io.*;
import java.util.*;
public class Main
{
static int n,k;
public void frontAndBack(long raise,int k)
{
int length
=String.
valueOf(raise
).
length();
long frontTemp=raise;
String front
= String.
valueOf((int)(frontTemp
/Math.
pow(10, length
-1))).
toString(); frontTemp
=(long) (frontTemp
%Math.
pow(10, length
-1));
for(int i=1;i<length && i<k;i++)
{
long quo,rem;
quo
=(long) (frontTemp
/Math.
pow(10, length
-i
-1)); rem
=(long) (frontTemp
%Math.
pow(10, length
-i
-1));
front
=front
+String.
valueOf(quo
).
toString(); frontTemp=rem;
}
long backTemp=raise;
backTemp
=(long) (backTemp
/Math.
pow(10,
1));
for(int i=1;i<length && i<k;i++)
{
long quo,rem;
quo
=(long)(backTemp
/Math.
pow(10,
1)); rem
=(long)(backTemp
%Math.
pow(10,
1));
back
=String.
valueOf(rem
).
toString()+back
; backTemp=quo;
}
}
public void calc()
{
long raise
=(long)Math.
pow(n,n
); frontAndBack(raise,k);
}
public static void main
(String[] args
) {
Scanner in
=new Scanner
(System.
in);
int t=in.nextInt();
while(t-->0)
{
n = in.nextInt();
k = in.nextInt();
new Main().calc();
}
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwoKcHVibGljIGNsYXNzIE1haW4KewogICAgc3RhdGljIGludCBuLGs7CiAgICBwdWJsaWMgdm9pZCBmcm9udEFuZEJhY2sobG9uZyByYWlzZSxpbnQgaykKCXsKCQlpbnQgbGVuZ3RoPVN0cmluZy52YWx1ZU9mKHJhaXNlKS5sZW5ndGgoKTsKCgkJbG9uZyBmcm9udFRlbXA9cmFpc2U7CgoJCVN0cmluZyBmcm9udCA9IFN0cmluZy52YWx1ZU9mKChpbnQpKGZyb250VGVtcC9NYXRoLnBvdygxMCwgbGVuZ3RoLTEpKSkudG9TdHJpbmcoKTsKCQlmcm9udFRlbXA9KGxvbmcpIChmcm9udFRlbXAlTWF0aC5wb3coMTAsIGxlbmd0aC0xKSk7CgoJCWZvcihpbnQgaT0xO2k8bGV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