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

hide comments
reo_j: 2012-09-14 17:36:48

@Jose Daniel Rodríguez Morales-in which case my code gives error..code id is 7203223..

Last edit: 2012-06-24 04:36:36
reo_j: 2012-09-14 17:36:48

@Denis -any tricky case plz...

Denis: 2012-09-14 17:36:48

I've right answer! Keep trying ;)

reo_j: 2012-09-14 17:36:48

my code is running correct but on spoj it gives wrong, code id is 7197491.
plz check it...!!!

Rishabh Sharma: 2012-09-14 17:36:48

my code is running perfectly fie..but still it is a WA..
could you please check thr output of my code.
ID 7031668

god_father: 2012-09-14 17:36:48

for this question 0^0=1
I got AC with that otherwise getting WA...

Saurabh Jain: 2012-09-14 17:36:48

my code is 600 bytes long and even then i am unable to submit the solution..!!!

The Vagabond: 2012-09-14 17:36:48

@ 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)

The Vagabond: 2012-09-14 17:36:48

wrt 2011-05-17 23:04:31 Robin Lee :
i agree u completely

Sivagaminathan: 2012-09-14 17:36:48

i get TLE for my code, how do i share it with someone who can help me ?


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