#include using namespace std; using ll=long long; using mat=vector>; int main(){ ll p,q,r,K; cin>>p>>q>>r>>K; const ll MOD=10; mat A={{1,1,1},{1,0,0},{0,1,0}}; auto multi=[&](mat X,mat Y){ mat res(3,vector(3)); for(int i=0;i<3;i++) for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ res[i][j]+=X[i][k]*Y[k][j]%MOD; res[i][j]%=MOD; } } return res; }; const int B=62; vector dbl(B); dbl[0]=A; for(int b=1;b=0;b--){ if(K>=(1LL<