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
excursionist: 2014-06-29 21:48:02

AC in Both c And Python
easy one

Shivam Bhardwaj: 2014-06-28 08:51:03

W.A. :| .... And its correct in my compilier -_-

HUNG-SI-QUAN: 2014-06-25 11:46:01

can anyone check my code
<snip>

Last edit: 2023-06-12 22:46:59
Akash Srivastava: 2014-05-29 21:37:52

Your solution is too long for this problem, the limit is 700 bytes! ??
Please help me out with this msg!!!

Rishab Banerjee: 2014-05-07 20:35:43

700 Bytes LOL... never seen such a problem before eliminate the spaces and indentations

मोहन: 2014-04-14 14:30:48

AC

[Lakshman]: 2014-04-08 17:01:02

@anonymous built in function is not efficient for large values, max values you can compute with pow is pow(2,63).You can solve this problem using modular exponentiation
http://en.wikipedia.org/wiki/Modular_exponentiation

Last edit: 2014-04-08 17:02:15
anonymous: 2014-04-08 16:10:00

Dont know why it is giving wrong answer. :\
<snip>

Last edit: 2023-06-12 22:47:03
Gaurav Agrawal: 2014-03-21 13:31:24

can some 1 check my code ?
<snip>

Last edit: 2023-06-12 22:47:08
Gaurav Agrawal: 2014-03-21 13:21:36

sry for posting code ..i'll not do it again...


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