a,b=$<.map &:to_i c=b%4 p b<1?1:case d=a%10 when 2;[6,2,4,8][c] when 3;[1,3,9,7][c] when 4;[6,4,6,4][c] when 7;[1,7,9,3][c] when 8;[6,8,4,2][c] when 9;[1,9,1,9][c] else d end