t=input()
while t>0:
t=t-1
m,n=input().split(" ")
m=int(m)
n=int(n)
m=m%10
n=n%4
if n==1:
print (m)
elif n==2:
print (m*m)%10
elif n==3:
print (m*m*m)%10
else:
print (m*m*m*m)%10
why this code is giving me NZEC error ? it is irritating me now. thanks