#line 1 "kyopro/main.cpp" #include #line 3 "kyopro_lib/base.hpp" #line 5 "kyopro_lib/base.hpp" using namespace std; using ll = long long; using ld = long double; using i2 = array; using i3 = array; using i4 = array; using f2 = array; using f3 = array; using f4 = array; template using min_pq = priority_queue, greater>; template using max_pq = priority_queue, less>; const ll INF = (1LL << 61); bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; } bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; } ll floor_div(ll a, ll b) { return a / b - (a % b != 0 && (a ^ b) < 0); } ll ceil_div(ll a, ll b) { return a / b + (a % b != 0 && (a ^ b) > 0); } ll floor_mod(ll a, ll b) { return a % b + (a % b != 0 && (a ^ b) < 0) * b; } mt19937 mt(time(0)); class xor_shift_128 { public: typedef uint32_t result_type; xor_shift_128(result_type seed = mt()) { set_seed(seed); } void set_seed(result_type seed) { a = seed = 1812433253 * (seed ^ (seed >> 30)); b = seed = 1812433253 * (seed ^ (seed >> 30)) + 1; c = seed = 1812433253 * (seed ^ (seed >> 30)) + 2; d = seed = 1812433253 * (seed ^ (seed >> 30)) + 3; } result_type gen() { result_type t = (a ^ (a << 11)); a = b; b = c; c = d; return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8)); } result_type operator()() { return gen(); } ll gen_range(ll min_inclusive, ll max_exclusive) { ll diff = max_exclusive - min_inclusive; assert(diff); return min_inclusive + gen() % diff; } static constexpr result_type max() { return numeric_limits::max(); } static constexpr result_type min() { return numeric_limits::min(); } private: result_type a, b, c, d; }; xor_shift_128 xorrand; template istream& operator>>(istream& is, array& a) { for (auto& x : a) is >> x; return is; } template ostream& operator<<(ostream& os, const array& a) { for (size_t i = 0; i < N; i++) os << (i ? " " : "") << a[i]; return os; } template istream& operator>>(istream& is, vector& v) { for (auto& x : v) is >> x; return is; } template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < (int)v.size(); i++) os << (i ? " " : "") << v[i]; return os; } template ostream& operator<<(ostream& os, const vector>& vv) { for (int i = 0; i < (int)vv.size(); i++) os << (i ? "\n" : "") << vv[i]; return os; } #define dbg(...) cerr << #__VA_ARGS__ << " = ", debug_print(__VA_ARGS__); void debug_print() { cerr << endl; } template void debug_print(const T& x, const Args&... args) { cerr << x; if constexpr (sizeof...(args) > 0) cerr << ", "; debug_print(args...); } struct sep { const char* s; sep(const char* s) : s(s) {} }; template void print(sep sp, const Args&... args) { int i = 0; ((cout << (i++ ? sp.s : "") << args), ...); cout << "\n"; } template void print(const Args&... args) { print(sep{" "}, args...); } template void print(const vector& v) { for (int i = 0; i < (int)v.size(); i++) cout << (i ? " " : "") << v[i]; cout << "\n"; } template void print(sep sp, const vector& v) { for (int i = 0; i < (int)v.size(); i++) cout << (i ? sp.s : "") << v[i]; cout << "\n"; } #line 4 "kyopro/main.cpp" bool is_multi = true; ll mod = 998244353; template constexpr T_VAL mod_inv(T_VAL a, T_MOD m) { if (gcd(a, m) != 1) { return 0; } T_VAL b = m, u = 1, v = 0; while (b > 0) { T_VAL t = a / b; a -= t * b, swap(a, b); u -= t * v, swap(u, v); } u %= m; if (u < 0) u += m; return u; } template constexpr T_VAL mod_pow(T_VAL a, T_VAL n, T_MOD m) { T_VAL res = 1; while (n > 0) { if (n % 2 == 1) res = res * a % m; a = a * a % m; n >>= 1; } return res; } void solve() { ll HA, AA, SA; ll HB, AB, SB; cin >> HA >> AA >> SA; cin >> HB >> AB >> SB; ll suba = (HA + AB - 1) / AB - 1; ll subb = (HB + AA - 1) / AA - 1; ll div = mod_pow(mod_inv(10LL, mod), abs(suba - subb), mod); ll mul = mod_pow(10LL, abs(suba - subb), mod) + mod - 1; ll ans = 0; if (suba >= subb) { ans = div * mul % mod; } else { } if (SA > SB) { div *= mod_inv(11, mod); div %= mod; ans += div * 10; } else if (SA == SB) { div *= mod_inv(2, mod); div %= mod; ans += div; } else { div *= mod_inv(11, mod); div %= mod; ans += div; } ans %= mod; cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); ll tests = 1; if (is_multi) { cin >> tests; } while (tests--) { solve(); } return 0; }