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
2013-08-30 16:26:08 Dyeison Carraro [FAJ]
700B? For that much? 450 is good...
2013-08-12 20:10:25 Lakshay Singhal
easy prob...done in both c++ nd python..
no need to worry about 0 0 case bcz in que it is given "a and b both are not 0."
2013-08-11 11:16:06 Ashish Tiwari
hai aasaan pr.... :(
2013-08-03 10:05:14 Raman Shukla
Very Easy problem... Silly mistake caused so many WAs...
2013-07-26 09:11:27 Pavan
yay accepted in first attempt
2013-07-21 20:15:24 aman kumar jha
<3 python
2013-06-23 08:19:48 kashyap murthy
any other trick case other than 0 0 ?

Last edit: 2013-06-23 08:20:00
2013-06-22 09:12:42 orange
@kamalesh,thanks silly mistake caused me >10 WA
2013-06-13 06:54:51 Joey Tribbiani
I dont get it. Tried all inputs possible, gives the right output. Why is this WA on spoj? Please help. Any test case for which the output is wrong?
<snip>

Last edit: 2023-06-12 22:48:01
2013-06-11 14:18:29 Ragesh
700 bytes limit is downright silly
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.