LASTDIG  The last digit
Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives him two numbers a and b. The problem consist of finding the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. You have to find the last digit of a^{b}.
Input
The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow. For each test case will appear a and b separated by space.
Output
For each test case output an integer per line representing the result.
Example
Input: 2 3 10 6 2
Output: 9 6
hide comments
rishisingh7012:
20211120 14:47:58
check for special cases 0 1 and 1 0 also. 

mohit_010:
20211110 08:03:17
think in a way that last digit of A will be the main cause to find the last digit of power ans ;; 

rapiram31:
20210909 14:22:54
There will be only two cases one is cycle from 1 (1 3 9 27 81) , second is cycle from x (1 4 16 64)


sabkx:
20210831 15:54:41
Euler theorem can solve this in O(1) for those that are stuck 

messifcbarcel:
20210813 03:02:22
Solved in first attempt instead of a compilation error because of that 700B thing


shubh3082:
20210615 11:08:08
i am getting correct solution for the problem on codechef but getting WA over here.


unwanted_coder:
20210601 07:40:35
AC in one go After reading about modular exponentiation


shankar_0x:
20210531 09:42:20
AC IN ONE GO, YALL NOOBS


loser_404:
20210531 06:09:35
good problem. Though (a=0 and b=0)=0 also get accepted. use modular exponentiation and use mod value as 10 for last digit 

anchord:
20210526 16:45:54
Great question, love it! 
Added by:  Jose Daniel Rodriguez Morales 
Date:  20081201 
Time limit:  1s 
Source limit:  700B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: GOSU 
Resource:  Own 