#include #include #include #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native") using namespace std; using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; //~ while (clock()<=69*CLOCKS_PER_SEC) #define ll long long #define ld long double #define pi pair #define pd pair #define ft first #define sd second #define st first #define nd second #define mp make_pair #define pb push_back #define eb emplace_back #define FOR(i,a,b) for(int i=(a); i<=(b);i++) #define F(i,a,b) FOR(i,(a),(b)-1) #define REV(i,a,b) for(int i=(a); i>=(b);i--) #define VI vector #define VPI vector #define VPD vector #define PI 3.14159265 #define all(x) (x).begin(), (x).end() #define sz(a) (int)((a).size()) #define int long long template void _dbg(const char *sdbg, TH h){cerr< void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="< C; typedef vector vd; #define rep(i, a, b) for(int i = a; i < (b); ++i) typedef pair pii; typedef vector vi; void fft(vector& a) { int n = sz(a), L = 31 - __builtin_clz(n); static vector> R(2, 1); static vector rt(2, 1); // (^ 10% faster if double) for (static int k = 2; k < n; k *= 2) { R.resize(n); rt.resize(n); auto x = polar(1.0L, acos(-1.0L) / k); rep(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2]; } vi rev(n); rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2; rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]); for (int k = 1; k < n; k *= 2) for (int i = 0; i < n; i += 2 * k) rep(j,0,k) { // C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled) /// include-line auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k]; /// exclude-line C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]); /// exclude-line a[i + j + k] = a[i + j] - z; a[i + j] += z; } } vd conv(const vd& a, const vd& b) { if (a.empty() || b.empty()) return {}; vd res(sz(a) + sz(b) - 1); int L = 32 - __builtin_clz(sz(res)), n = 1 << L; vector in(n), out(n); copy(all(a), begin(in)); rep(i,0,sz(b)) in[i].imag(b[i]); fft(in); for (C& x : in) x *= x; rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]); fft(out); rep(i,0,sz(res)) res[i] = imag(out[i]) / (4 * n); return res; } typedef vector vl; template vl convMod(const vl &a, const vl &b) { if (a.empty() || b.empty()) return {}; vl res(sz(a) + sz(b) - 1); int B=32-__builtin_clz(sz(res)), n=1< L(n), R(n), outs(n), outl(n); rep(i,0,sz(a)) L[i] = C((int)a[i] / cut, (int)a[i] % cut); rep(i,0,sz(b)) R[i] = C((int)b[i] / cut, (int)b[i] % cut); fft(L), fft(R); rep(i,0,n) { int j = -i & (n - 1); complex unit = 1i; outl[j] = (L[i] + conj(L[j])) * R[i] / (2.0 * n); outs[j] = (L[i] - conj(L[j])) * R[i] / (2.0 * n) / unit; } fft(outl), fft(outs); rep(i,0,sz(res)) { ll av = (ll)(real(outl[i])+.5), cv = (ll)(imag(outs[i])+.5); ll bv = (ll)(imag(outl[i])+.5) + (ll)(real(outs[i])+.5); res[i] = ((av % M * cut + bv) % M * cut + cv) % M; } return res; } void solve() { int n, k; cin >> n >> k; VI w(n + 1); FOR(i, 1, n) cin >> w[i]; pre[0][0][0] = 1; suf[n + 1][0][0] = 1; FOR(i, 1, n) { FOR(j, 0, k) { pre[i][0][0] = 1; F(l, 1, n) { if (j - w[i] >= 0) (pre[i][j][l] += pre[i - 1][j - w[i]][l - 1]) %= MOD; (pre[i][j][l] += pre[i - 1][j][l]) % MOD; } } } REV(i, n, 1) { FOR(j, 0, k) { suf[i][0][0] = 1; F(l, 1, n) { if (j - w[i] >= 0) (suf[i][j][l] += suf[i + 1][j - w[i]][l - 1]) %= MOD; (suf[i][j][l] += suf[i + 1][j][l]) %= MOD; } } } FOR(i, 1, n) { FOR(l, 1, n - 1) { int r = 0; FOR(l1, 0, l) { VI v1(k + 1), v2(k + 1); FOR(j, 0, k) { v1[j] = pre[i - 1][j][l1]; v2[j] = suf[i + 1][j][l - l1]; } VI res = convMod(v1, v2); FOR(j, k - w[i] + 1, k) { r += res[j]; } } cout << r % MOD << " "; } cout << "\n"; } } int32_t main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cout<>test; F(_test, 0, test){ //cout<<"Case #"<<_test + 1<<": "; solve(); // if(_test == 1) // return 0; } return 0; } /* 3 B B.. ... ... 3 B BBB BBB BBB 3 K KKK KKK KKK */