#include<bits/stdc++.h> usingnamespace std; #define endl '\n' #define debug(a) cout<<#a<<"="<<a<<endl; #define int long long // #define x first // #define y second typedeflonglong LL; typedef pair<int,int> PII; typedef pair<double,double> PDD; constdouble eps=1e-8; bool multi=0; constint N=1e4+10; int m,n;
structPoint { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) { } }p[N],P[N];
intsign(double x)// 符号函数 { if (fabs(x) < eps) return0; if (x < 0) return-1; return1; }
intcmp(double x, double y)// 比较函数 { if (fabs(x - y) < eps) return0; if (x < y) return-1; return1; } Point operator + (Point A, Point B) {returnPoint(A.x + B.x, A.y + B.y);}
Point operator - (Point A, Point B) {returnPoint(A.x - B.x, A.y - B.y);}
Point operator * (Point A, double p) {returnPoint(A.x * p, A.y * p);}
Point operator / (Point A, double p) {returnPoint(A.x / p, A.y / p);}
doubledot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
doubleget_length(Point a) { returnsqrt(dot(a, a)); }
doublecross(Point a, Point b) { return a.x * b.y - b.x * a.y; }
doubledistance_to_line(Point p, Point a, Point b) { Point v1 = b - a, v2 = p - a; returnfabs(cross(v1, v2) / get_length(v1)); }
doubledistance_to_segment(Point p, Point a, Point b) { if (cmp(a.x,b.x)==0&&cmp(a.y,b.y)==0) returnget_length(p - a); Point v1 = b - a, v2 = p - a, v3 = p - b; if (sign(dot(v1, v2)) < 0) returnget_length(v2); if (sign(dot(v1, v3)) > 0) returnget_length(v3); returndistance_to_line(p, a, b); }
#include<bits/stdc++.h> usingnamespace std; #define endl '\n' #define debug(a) cout<<#a<<"="<<a<<endl; #define int long long //#define x first //#define y second typedeflonglong LL; typedef pair<int,int> PII; typedef pair<double,double> PDD; constdouble eps=1e-8; bool multi=1; constint mod=998244353;
//a ^ b mod p intqpow(int a,int b,int p){ longlong res=1%p; while(b){ if(b&1) res=res*a%p; a=(longlong)a*a%p; b>>=1; } return res; } constint N=1e6+10;
int sum[N]; int C[N]; int s[N];
voidsolve(){ int n,m,a,b; cin>>n>>m>>a>>b; for(int i=1;i<=n;i++){ sum[i]=(sum[i-1]+qpow(i,m,mod)%mod)%mod; } int invab=a*qpow(b,mod-2,mod)%mod; int invbab=(b-a)*qpow(b,mod-2,mod)%mod; // pow[0]=qpow(invab,n); // for(int i=1;i<=n;i++){ // pow[i]=pow[i-1]*qpow(invb,mod-2,mod) // } int inva=qpow(a,mod-2,mod); int invba=qpow(b-a,mod-2,mod); s[0]=qpow(b-a,n,mod)*qpow(qpow(b,mod-2,mod),n,mod)%mod; for(int i=1;i<=n;i++){ s[i]=s[i-1]*a%mod*invba%mod; } C[0]=1; int invbb=qpow(qpow(b,mod-2,mod),n,mod); for(int i=1;i<=n;i++){ C[i]=(C[i-1]*(n-i+1)%mod*qpow(i,mod-2,mod))%mod; } int ans=0; for(int i=1;i<=n;i++){ ans=(ans+C[i]*s[i]%mod*sum[i]%mod)%mod; } cout<<ans%mod<<endl; }
signedmain(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int TTT=1; if(multi) cin>>TTT; while(TTT--){ solve(); }
#include<bits/stdc++.h> usingnamespace std; #define endl '\n' #define debug(a) cout<<#a<<"="<<a<<endl; #define int long long //#define x first //#define y second typedeflonglong LL; typedef pair<int,int> PII; typedef pair<double,double> PDD; constdouble eps=1e-8; bool multi=1; constint N=1e6+10; int n; int p[N],sz[N],fa[N],d[N]; int depth[N]; int root; int ans;
#include<bits/stdc++.h> usingnamespace std; #define endl '\n' #define debug(a) cout<<#a<<"="<<a<<endl; #define int long long //#define x first //#define y second typedeflonglong LL; typedef pair<int,int> PII; typedef pair<double,double> PDD; constdouble eps=1e-8; constint mod=1e9+7; bool multi=1; int n,m; constint N=1e6+10; int dg[N]; int cnt[N]; int fac[N],infac[N];
//a ^ b mod p intqpow(int a,int b,int p){ longlong res=1%p; while(b){ if(b&1) res=res*a%p; a=(longlong)a*a%p; b>>=1; } return res; }