新学的黑科技,感觉好nb ~
#include <bits/stdc++.h>
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
const ll mod=998244353;
inline ll qpow(ll x,ll y)
{
ll tmp=1;
x=x%mod;
y=(y%(mod-1)+mod-1)%(mod-1);
for(;y;y>>=1,x=x*x%mod) if(y&1) tmp=tmp*x%mod;
return tmp;
}
inline ll INV(int x) { return qpow(x,mod-2); }
ll n;
int s,a[5];
ll F(ll i,ll x)
{
ll re=qpow(x+s,n);
return re*qpow(x,i-n)%mod;
}
int main()
{
setIO("input");
int i,j,T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%d",&n,&s);
for(i=0;i<4;++i) scanf("%d",&a[i]);
int w=qpow(3,(mod-1)/4), inv=qpow(w,mod-2);
int ans=0;
for(i=0;i<=3;++i) for(int k=0,t=1;k<=3;++k,t=1ll*t*inv%mod)
ans=(ans+1ll*F(i,t)*a[i]%mod)%mod;
ans=1ll*ans*qpow(4,mod-2)%mod;
printf("%d
",ans);
}
return 0;
}