The last digit in an exponentation In this task you will be given A (less than 10000 digits long) and B (less than 2^64), and you will need to compute the last digit of (A &middot; A &middot; A &middot; ... &middot; A (B times)). 

The inputs A and B are given in a single line separated by a blank; the inputs are terminated by EOF.

Input

34543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222345432323213232432424345445334453434324343111122234543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222345432323213232432424345445334453434324343111122234543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222 22337254775808
38758436543765743875437656358764347568437658743658743454354645645543532487548758475847684756897548758457843758437584758478574857438758436587436587436587643875643856783478743658743658764387564387564378658437658743658743687564387564387564765746576475647564756475465746574675647654765476547534587545689475689748574385743765874585743857843765893748643587438957458754376543265874387564384764367584375874758943267632487564357 54545454123
6777744348435743587643756438765436574587564354375674365645643675 23232    
3875843654376574357 54545454


Output

6
3
5
9


Constraints


Don't use any inbuilt function or overloaded operators to compute AB (you don't really need to compute that at all).
Shortest solution wins!
J - 52 characters

wd,.10|(^12+12&amp;|)/"1(".@{:`".;._2@,&amp;'x ');._2(1!:1)3


Passes all tests given, though only if the trailing spaces on the third input are removed (I'm guessing this was unintentional).

Solution will work in j602 in console mode (e.g. in terminal, emacs j-shell, etc.). It will not work in j701 (no wd).

Explanation &amp; Mathiness:

The 'magic number' 12 is the LCM of the lengths of the "last digit" tables found in the other answers. All digits repeat with periods 1,2,3 or 4 so they will also repeat with period 12. Adding twelve to that fixes cases where b mod 12 = 0. My solution computes (Last digit of A)^(12+(B mod 12)), giving a number with the same last digit. (I considered a sneaky broken solution eliminating the three characters '12+' by using e.g. B mod 96 where no examples were likely to collide...)