#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using mint = modint998244353; // using mint = modint1000000007; constexpr ll INF = (1LL << 60); constexpr int INF32 = (1 << 30); template using vc = vector; template using vv = vector>; using vi = vc; using vvi = vv; using vl = vc; using vvl = vv; using vs = vc; using vvs = vv; using vb = vc; using vvb = vv; using vmint = vc; using vvmint = vv; using pii = pair; using pll = pair; #define rep(i,n) for(ll i=0; i<(ll)(n); i++) #define drep(i,n) for(ll i=(ll)(n)-1; i>=0; i--) #define rrep(i,n) for(ll i=1; i<=(ll)(n); i++) #define nfor(i,a,b) for(ll i=(ll)(a); i<(ll)(b); i++) #define dfor(i,a,b) for(ll i=(ll)(a)-1; i>=(ll)(b); i--) #define nall(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() template istream& operator>>(istream& is, vector& v) { for (auto& x : v) is >> x; return is; } template istream& operator>>(istream& is, pair& p) { return is >> p.first >> p.second; } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } void YES() { cout << "Yes\n"; } void NO() { cout << "No\n"; } void yn(bool ok) { cout << (ok ? "Yes" : "No") << '\n'; } template void print(const vector& v) { for (int i = 0; i < (int)v.size(); i++) { if (i) cout << ' '; cout << v[i]; } cout << '\n'; } template void print(const vector>& v) { for (const auto& row : v) { print(row); } } void print(ld x) { cout << fixed << setprecision(20) << x << '\n'; } ll ceil_div(ll a, ll b) { assert(b != 0); ll q = a / b; ll r = a % b; if (r != 0 && ((r > 0) == (b > 0))) q++; return q; } int main() { int T; cin >> T; const mint q = mint(1)/10; const mint inv2 = mint(1) / 2; const mint inv11 = mint(1) / 11; rep(t,T) { ll hc,ac,sc,hg,ag,sg; cin >> hc >> ac >> sc >> hg >> ag >> sg; ll C = ceil_div(hg,ac); ll G = ceil_div(hc,ag); mint ans = 0; if (sc == sg) { if (C < G) { ans = 1 - q.pow(G - C) * inv2; } else if (C == G) { ans = inv2; } else { ans = q.pow(C - G) * inv2; } } else if (sc > sg) { if (C < G) { ans = 1 - q.pow(G - C) * inv11; } else if (C == G) { ans = mint(10) * inv11; } else { ans = mint(10) * q.pow(C - G) * inv11; } } else { if (C < G) { ans = 1 - mint(10) * q.pow(G - C) * inv11; } else if (C == G) { ans = inv11; } else { ans = q.pow(C - G) * inv11; } } cout << ans.val() << endl; } }