LASTDIG2 - The last digit re-visited


Pappu 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 two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Pappu with his problem. You are given two integer numbers: the base a (number of digits d, such that 1 <= d <= 1000) and the index b (0 <= b <= 922*10^15). 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:
3
3 10
6 2
150 53

Output:
9
6
0

Source limit is 700 Bytes.


hide comments
th3ghost: 2019-07-29 19:36:39

just use python for this

aj_254: 2019-05-23 21:58:17

one liner in python print(pow(a,b,10))

r210397: 2018-06-28 10:26:53

very easy ac at last

dennislo: 2018-06-13 23:24:11

Test cases are very weak:

1
4 8

Even if your solution outputs "1", you will still get AC (assuming you handled the edge case)

s_a_k_s_h_a_m: 2018-06-12 15:04:16

@srijan123j it will be 0
this costed me 2 WA

shashankpathak: 2018-05-03 08:07:40

source limit 700 bytes i am not able to space optimize my code !

nsh__: 2018-02-21 20:08:06

AC in One GO !!!

Michael Kharitonov: 2018-01-07 10:56:46

@diptark_bose: EOL was converted to CRLF, use "Choose file" to prevent this from happening.

Last edit: 2018-01-07 10:57:07
diptark_bose: 2018-01-05 06:00:44

My source code is an exact 697 characters (which is <700 bytes). Still getting "Exceeding 700 bytes error"!!

bayulaxana: 2018-01-01 06:50:39

don't forget if b can be 0..
cost me much WA.. :(


Added by:Hari
Date:2009-12-27
Time limit:1s
Source limit:700B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:harrydcoder