#include using namespace std; typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VL; typedef vector VVL; typedef pair PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF (1LL<<25) //33554432 #define PI 3.14159265359 #define EPS 1e-12 //#define int ll signed main(void) { string n, m; cin >> n >> m; if(m == "0") { cout << 1 << endl; return 0; } int a = n[n.size()-1] - '0', b = stoi(m.substr(m.size()-2, 2)), cnt[4]; cnt[0] = a; FOR(i, 1, 4) { cnt[i] = (cnt[i-1]*a) % 10; cout << cnt[i] << " "; } cout << endl << b << endl; if(b == 0) cout << cnt[3] << endl; else cout << cnt[(b-1)%4] << endl; return 0; }