#include #include using namespace std; using namespace atcoder; using ll = long long; using mint=modint998244353; using ld = long double; const ll infl = 1LL << 60; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const vector dx = {1, 0, -1, 0}; const vector dy = {0, 1, 0, -1}; template using vc = vector; template using vvc = vc>; template using vvvc = vc>; using vi = vc; using vvi = vvc; using vl = vc; using vvl = vvc; using vvvl = vvc; using vvvvl = vvc; using vs = vc; using vvs = vvc; using P = pair; #define nrep(i,n) for (ll i = 0; i < (n); ++i) #define nfor(i,s,n) for(ll i=s;i using pq = priority_queue>;//★大きい順に取り出す コスト,頂点 bfs系で使う 小さい順じゃないですABC305E template using pq_g = priority_queue, greater>;//小さい順に取り出す ダイクストラ法で使う #define cout(n) cout<>= 1; } return res; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); vvl a = {{1, 2}, {3, 4}}; vvl b = {{5}, {7}}; cin >> a[0][0] >> a[0][1] >> a[1][0] >> a[1][1]; cin >> b[0][0] >> b[1][0]; ll N, K; cin >> N >> K; ll offset = 1e9; a[0][0] = (a[0][0] + K * (offset / K)) % K; a[0][1] = (a[0][1] + K * (offset / K)) % K; a[1][0] = (a[1][0] + K * (offset / K)) % K; a[1][1] = (a[1][1] + K * (offset / K)) % K; b[0][0] = (b[0][0] + K * (offset / K)) % K; b[1][0] = (b[1][0] + K * (offset / K)) % K; // vv_cout(a); // vv_cout(b); vvl c = matpow(a, N, K); // vv_cout(c); c = matmul(c, b, K); cout(c[0][0] << ' ' << c[1][0]); return 0; }