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
amit_1997rock: 2015-12-10 19:46:28

make sure u covert the case when exp is 0

hanstan: 2015-11-12 12:57:28

Careful of the first number input, costed me 1 WA.
<700B in C++ is a bit hard to develop

dk619: 2015-10-27 12:46:51

Difficult to maintain <700B in c++

Anurag Sharma: 2015-09-13 05:57:11

AB TAK CHAPPAN (56) :P

chiflowmaxx: 2015-08-22 12:40:51

cho !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Rajat Varshney: 2015-08-06 11:47:22

Good for boundary conditions

Yuvak Patel: 2015-07-26 19:48:19

AC in 2nd go, first time use of gets without fflush(stdin) cost me one WA ; 20 up

mohit: 2015-07-07 09:26:59

same as lastdig.. only string required for base.. silly mistake resulted in 2 SISSEGV . watch out for '\0' at the end of string.

r0bo_dart: 2015-06-14 20:31:30

This problem is exact same to LASTDIG. Just handle a method to get 1000 digit long input.
HINT: not all of the digits of base are important.

saifullah: 2015-06-14 18:00:38

what the hell!! input 150 0 gives 0 still AC??
why can any one explain?


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