LASTDIG2  The last digit revisited
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
kolahzary:
20160422 03:54:24
@prateekmathur1991


kolahzary:
20160422 02:54:04
Simple mistake in understanding the problem actually ate my day :


vikash1143:
20160309 05:56:10
Done in O(n/4)..0.02..!!! 

akazad133032:
20160221 08:42:02
Hey,,, it's a pattern .... :) :) 

akash :
20160126 18:49:02
Never mix 'scanf' and 'cin' when synchronization is turned off! Lesson learned! 

prateekmathur1991:
20160112 13:22:14
Runs fine on my PC, and ideone as well, but shows NZEC after submitting on SPOJ....!!! 

dokz:
20160106 10:56:10
Yay! 650 bytes in C# :) 

sarthak_8:
20160104 19:50:52
Got an AC finally after 4 WA. Don't know why it was giving WA when I took b in a string. Later taking b as LLI gave an AC. The code isn't long. I managed to get an AC with a code of 373B 

DEVVRAT GUPTA:
20151222 07:55:42
Please don't use bits/stdc++ header here as the limit is 700 bytes only... 

AASHISH KUMAR:
20151222 06:41:39
2 WA for long long int :(

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