import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String a=sc.next(); String b = sc.next(); long c = Long.parseLong(a.charAt(a.length()-1)+""); long aa = 0; if(b.length()>1){ aa = Long.parseLong(b.substring(b.length()-2, b.length())); }else{ aa=Long.parseLong(b.charAt(b.length()-1)+""); } aa-=1; aa%=4; aa++; System.out.println(aa+" "+(Math.pow(c, aa)%10)); } }