fork download
  1. import java.util.*;
  2.  
  3. class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int testCases = sc.nextInt();
  7. while ((testCases--) > 0) {
  8. String x = sc.next();
  9. int lastDigit = x.charAt(x.length() - 1) - '0';
  10. int n = sc.nextInt();
  11. if (n == 0) {
  12. System.out.println("1");
  13. } else {
  14. n = ((n % 4) == 0) ? 4 : n % 4;
  15. System.out.println((int) Math.pow(lastDigit, n) % 10);
  16. }
  17. }
  18. }
  19. }
Success #stdin #stdout 0.13s 51580KB
stdin
5
10 11
11 21
16 32
35 23
10 0
stdout
0
1
6
5
1