#include using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector vi; typedef vector vvi; typedef pair pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inline void RI(i64 &i) {scanf("%lld", &(i));} inline void RVI(vi &v) { for(i64 i=0;i inline bool IN(T &S, const typename T::key_type &key) { return S.find(key) != S.end(); } template inline bool ON(const T &b, i64 idx) { return ((T(1) << idx) & b) != 0; } template struct modint { modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {} using this_type = modint; T val; this_type operator++(int) { this_type ret = *this; val++; val %= M; return ret; } this_type operator--(int) { this_type ret = *this; val += M-1; val %= M; return ret; } this_type &operator++() { val++; val %= M; return *this; } this_type &operator--() { val += M-1; val %= M; return *this; } this_type operator+() const { return *this; } this_type operator-() const { return this_type(M-val); }; friend this_type operator+(const this_type &lhs, const this_type &rhs) { return this_type(lhs) += rhs; } friend this_type operator-(const this_type &lhs, const this_type &rhs) { return this_type(lhs) -= rhs; } friend this_type operator*(const this_type &lhs, const this_type &rhs) { return this_type(lhs) *= rhs; } friend this_type operator/(const this_type &lhs, const this_type &rhs) { return this_type(lhs) /= rhs; } this_type pow(long long b) const { this_type ret = 1, a = *this; while(b != 0) { if(b % 2 != 0) { ret *= a; } b /= 2; a = a * a; } return ret; } this_type inv() const { return pow(M-2); } this_type& operator+=(const this_type &rhs) { val += rhs.val; val %= M; return *this; } this_type& operator-=(const this_type &rhs) { val += M - rhs.val; val %= M; return *this; } this_type& operator*=(const this_type &rhs) { val *= rhs.val; val %= M; return *this; } this_type& operator/=(const this_type &rhs) { *this *= rhs.inv(); return *this; } friend bool operator==(const this_type &lhs, const this_type &rhs) { return lhs.val == rhs.val; } friend bool operator!=(const this_type &lhs, const this_type &rhs) { return lhs.val != rhs.val; } T mod() const {return M;} }; using mi = modint<998244353>; //using mi = modint<1000000007>; using vmi = vector; using vvmi = vector; // row initializers template vector init_row(size_t cols) { return vector(cols, 0); } template> class matrix_ { public: using this_type = matrix_; matrix_(size_t rows, size_t cols) { assert(rows > 0 && cols > 0); data.resize(rows, init_row(cols)); } matrix_(const vector &values) { assert(!values.empty()); data = values; } T& operator()(size_t r, size_t c) { assert(0 <= r && r < rows()); assert(0 <= c && c < cols()); return data[r][c]; } const T& operator()(size_t r, size_t c) const { assert(0 <= r && r < rows()); assert(0 <= c && c < cols()); return data[r][c]; } ///// // matrix-matrix operations this_type &operator+=(const this_type &rhs) { assert(rows() == rhs.rows() && cols() == rhs.cols()); for(size_t r=0;r data; }; using matrix = matrix_; matrix matpow(const matrix &a, i64 p) { matrix res(a.rows(), a.cols()); for(i64 i=0;i> MA >> NA >> S; i64 MB, NB, T; cin >> MB >> NB >> T; i64 K; cin >> K; i64 SIZE = S + T + 1; matrix XA(SIZE, SIZE), XB(SIZE, SIZE); // X = idx - T auto v2i = [&](i64 v) { return v + T; }; // make XA XA(0, 0) = XA(S+T, S+T) = 1; mi PA = mi(MA) * mi(NA).inv(); mi RA = 1 - PA; for(i64 v=-T+1;v-T;--u) { XB(v2i(u), v2i(v)) = XB(v2i(u+1), v2i(v)) * PB; PS += XB(v2i(u), v2i(v)); } XB(v2i(-T), v2i(v)) = 1 - PS; } #if 0 REP(0, SIZE, i) { REP(0, SIZE, j) { cerr << XA(i,j).val << " "; } cerr << endl; } REP(0, SIZE, i) { REP(0, SIZE, j) { cerr << XB(i,j).val << " "; } cerr << endl; } #endif matrix X = XB * XA; #if 0 REP(0, SIZE, i) { REP(0, SIZE, j) { cerr << X(i,j).val << " "; } cerr << endl; } #endif matrix XP = matpow(X, K); matrix U(SIZE, 1); U(v2i(0), 0) = 1; matrix V = XP * U; #if 0 REP(0, SIZE, i) { cerr << U(i,0).val << " "; } cerr << endl; REP(0, SIZE, i) { cerr << V(i,0).val << " "; } cerr << endl; #endif WI(V(v2i(S), 0).val); WI(V(v2i(-T), 0).val); return 0; }