a[2],c,s;main(f){for(;read(0,&c,1);)c-10?a[f]=a[f]%10*10+c-48,s+=1-f:f--;s=!printf("%d",(f=pow(a[1]%10,*a%4+(s-1||*a)*4))%10);}