https://www.acmicpc.net/problem/1009
n=int(input()) for i in range(n): a,b=map(int,input().split()) num=1 for _ in range(b): num=(num*a)%10 print(10 if(num==0) else num)