#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int p1, p2;
int inv(int x) {
if(x <= 1) return 1;
return 1ll * (mod - mod / x) * inv(mod % x) % mod;
}
int calc(int x, int y) {
if(y <= 0) return 1;
if(x <= 0) return 0;
return (1ll * p1 * calc(x, y - x) + 1ll * p2 * calc(x - y, y)) % mod;
}
int main() {
ios::sync_with_stdio(0); cin.tie(nullptr);
int T; cin >> T;
for(; T; --T) {
int x, y, s; cin >> x >> y;
cin >> p1 >> p2 >> s; s = p1 + p2;
p1 = 1ll * p1 * inv(s) % mod;
p2 = 1ll * p2 * inv(s) % mod;
cout << calc(x, y) << "\n";
}
return 0;
}