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 ab.

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

Added by:Jose Daniel Rodriguez Morales
Date:2008-12-01
Time limit:1s
Source limit:700B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: GOSU
Resource:Own

hide comments
2012-09-14 17:36:48 reo_j
@Jose Daniel Rodríguez Morales-in which case my code gives error..code id is 7203223..

Last edit: 2012-06-24 04:36:36
2012-09-14 17:36:48 reo_j
@Denis -any tricky case plz...
2012-09-14 17:36:48 Denis
I've right answer! Keep trying ;)
2012-09-14 17:36:48 reo_j
my code is running correct but on spoj it gives wrong, code id is 7197491.
plz check it...!!!
2012-09-14 17:36:48 Rishabh Sharma
my code is running perfectly fie..but still it is a WA..
could you please check thr output of my code.
ID 7031668
2012-09-14 17:36:48 god_father
for this question 0^0=1
I got AC with that otherwise getting WA...
2012-09-14 17:36:48 Saurabh Jain
my code is 600 bytes long and even then i am unable to submit the solution..!!!
2012-09-14 17:36:48 The Vagabond
@ 2010-12-14 22:28:44 The Financier
Why whitespaces are also calculated ? =\

this is becz ur code is stored at SPOJ server which takes SPACE(which costs)
2012-09-14 17:36:48 The Vagabond
wrt 2011-05-17 23:04:31 Robin Lee :
i agree u completely
2012-09-14 17:36:48 Sivagaminathan
i get TLE for my code, how do i share it with someone who can help me ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.