https://www.acmicpc.net/problem/1009
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
for(int i=0;i<n;i++){
int a=s.nextInt();
int b=s.nextInt();
int num=1;
for(int j=0;j<b;j++) num=(num*a)%10;
if(num==0) num=10;
System.out.println(num);
}
}
}