#line 1 "prayground.cpp" #include #include #define rep(i,n) for (int i = 0; i < int(n); ++i) #define repp(i,m,n) for (int i = m; i < int(n); ++i) #define reb(i,n) for (int i = int(n)-1; i >= 0; --i) #define all(v) v.begin(),v.end() using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair; using PL = pair; using pdd = pair; using pil = pair; using pli = pair; templateistream &operator>>(istream &is,vector &v){for(auto &e:v)is>>e;return is;} templatebool range(T a,T b,T x){return (a<=x&&xbool rrange(T a,T b,T c,T d,T x,T y){return (range(a,c,x)&&range(b,d,y));} template T rev(const T& str_or_vec){T res = str_or_vec; reverse(res.begin(),res.end()); return res; } templatebool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;} templatebool chmax(T &a,const T &b){if(avoid uniq(vector &v){sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());} templatevoid print(pair a); templatevoid print(vector v); templatevoid print(vector> v); void print(){ putchar(' '); } void print(bool a){ printf("%d", a); } void print(int a){ printf("%d", a); } void print(long a){ printf("%ld", a); } void print(long long a){ printf("%lld", a); } void print(char a){ printf("%c", a); } void print(char a[]){ printf("%s", a); } void print(const char a[]){ printf("%s", a); } void print(long double a){ printf("%.15Lf", a); } void print(const string& a){ for(auto&& i : a) print(i); } void print(unsigned int a){ printf("%u", a); } void print(unsigned long long a) { printf("%llu", a); } template void print(const T& a){ cout << a; } int out(){ putchar('\n'); return 0; } template int out(const T& t){ print(t); putchar('\n'); return 0; } template int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; } templatevoid print(pair a){print(a.first);print(),print(a.second);} templatevoid print(vector v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())print();}} templatevoid print(vector> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())out();}} void yes(){out("Yes");} void no (){out("No");} void yn (bool t){if(t)yes();else no();} void fast_io(){cin.tie(0); ios::sync_with_stdio(0); cout< dx = {0,1,0,-1,1,1,-1,-1}; const vector dy = {1,0,-1,0,1,-1,-1,1}; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const string alp = "abcdefghijklmnopqrstuvwxyz"; const string NUM = "0123456789"; } // namespace noya2 using namespace noya2; using mint = modint998244353; //using mint = modint1000000007; //using mint = modint; void out(mint a){out(a.val());} void out(vector a){vector b(a.size()); rep(i,a.size()) b[i] = a[i].val(); out(b);} void out(vector> a){for (auto v : a) out(v);} #line 2 "convolution.hpp" #line 2 "NTT.hpp" #line 4 "NTT.hpp" template struct NTT{ using mint = static_modint; NTT(){init();}; static void FFT(vector &a){ int n = a.size(); int siz = 1; while (siz < n) siz <<= 1; a.resize(siz); fft(a,1); } static void IFFT(vector &a){ int n = a.size(); int siz = 1; while (siz < n) siz <<= 1; mint div = mint(siz).inv(); a.resize(siz); fft(a,-1); for (auto &x : a) x *= div; } static void DFT(vector &a, int inv){fft(a,inv);} static vector multiply(vector a, vector b){ vector na(a.size()), nb(b.size()); for (int i = 0; i < (int)a.size(); i++) na[i] = a[i]; for (int i = 0; i < (int)b.size(); i++) nb[i] = b[i]; vector nc = multiply(na,nb); vector c(nc.size()); for (int i = 0; i < (int)nc.size(); i++) c[i] = nc[i].val(); return c; } static vector multiply(vector a, vector b){ int n = a.size() + b.size() - 1; int siz = 1; while (siz < n) siz <<= 1; a.resize(siz), b.resize(siz); FFT(a), FFT(b); for (int i = 0; i < siz; i++) a[i] *= b[i]; IFFT(a); a.resize(n); return a; } private: static static_modint g; static int limit; static vector>root, inv_root; static constexpr mint primitive_root(const long long &mo){ if (mo == 2) return mint(1); if (mo == 167772161) return mint(3); if (mo == 469762049) return mint(3); if (mo == 754974721) return mint(11); if (mo == 998244353) return mint(3); if (mo == 1224736769)return mint(3); return mint(); // atode kaku } static void init(){ if (!root.empty()) return ; g = primitive_root(m); long long now = m-1; while ((now & 1) == 0) now >>= 1, limit++; root.resize(limit+1,1), inv_root.resize(limit+1,1); root[limit] = g.pow(now), inv_root[limit] /= root[limit]; for(int i = limit-1; i >= 0; i--){ root[i] = root[i+1] * root[i+1]; inv_root[i] = inv_root[i+1] * inv_root[i+1]; } } static int bits_msb(int v){ v = v | (v >> 1); v = v | (v >> 2); v = v | (v >> 4); v = v | (v >> 8); v = v | (v >> 16); return v ^ (v >> 1); } static int pre(int v, int n){ return v ^ (n - bits_msb(v)); } static void fft(vector &a, int inv){ init(); int n = a.size(); if (n == 1) return ; int d = 0; while ((n >> d & 1) == 0) d++; vector idx(n); idx[n-1] = n-1; for (int i = n-2; i >= 0; i--) idx[i] = pre(idx[i+1],n); vector na = a; for (int i = 0; i < n; i++) a[i] = na[idx[i]]; for (int i = 0; i < d; i++){ int width = 1 << (i+1); vector gp(width/2,1); if (inv == 1) for (int j = 0; j < width/2-1; j++) gp[j+1] = gp[j] * root[i+1]; if (inv == -1) for (int j = 0; j < width/2-1; j++) gp[j+1] = gp[j] * inv_root[i+1]; for (int j = 0; j < n; j += width){ for (int k = 0; k < width/2; k++){ mint lhs = a[j+k], rhs = a[j+k+width/2] * gp[k]; a[j+k] = lhs + rhs; a[j+k+width/2] = lhs - rhs; } } } } }; template int NTT::limit=0; template vector>NTT::root=vector>(); template vector>NTT::inv_root=vector>(); template static_modintNTT::g=static_modint(); #line 5 "convolution.hpp" namespace noya2{ using ll = long long; using namespace std; template vector convolution(vector a, vector b){ // T = ll, modint998244353 return NTT<998244353>::multiply(a,b); } template vector arbitrary_mod_convolution(vector a, vector b){ static constexpr ll m1 = 167772161, m2 = 469762049, m3 = 1224736769; static constexpr ll m1_inv_m2 = 104391568, m12_inv_m3 = 721017874; const ll m12_mod = 78812994116517889LL % MOD; auto c1 = NTT::multiply(a,b); auto c2 = NTT::multiply(a,b); auto c3 = NTT::multiply(a,b); vector res(c1.size()); for (int i = 0; i < (int)res.size(); i++){ ll t1 = c1[i]; ll t2 = (c2[i] - c1[i]) * m1_inv_m2 % m2; if (t2 < 0) t2 += m2; ll t3 = (c3[i] - (t1 + t2 * m1) % m3) * m12_inv_m3 % m3; if (t3 < 0) t3 += m3; res[i] = (t1 + t2 * m1 + t3 * m12_mod) % MOD; if (res[i] < 0) res[i] += MOD; } return res; } } // namespace noya2 #line 78 "prayground.cpp" void solve(){ int n, m; cin >> n >> m; vector a(n); cin >> a; const ll md = 1< b(n-1-i); rep(j,n-1-i) b[j] = (a[j]+a[j+1])*(a[j]+a[j+1]) % md; swap(a,b); } out(a[0]); return ; } int nn = n-100; vector b(nn+1,1); auto get = [&](int x){ int t = 0; while ((x & 1) == 0){ t++; x >>= 1; } return P(x,t); }; ll cur = 1; int ni = 0; for (int i = 1; i <= nn; i++){ auto [pv, pt] = get(nn+1-i); cur = cur * pv % md; ni += pt; auto [qv, qt] = get(i); cur = cur * inv_mod(qv,md) % md; ni -= qt; if (ni >= m) b[i] = 0; else b[i] = (cur << ni) % md; } rep(i,nn+1) if (i % 2 == 1) b[i] = (md-b[i])%md; auto c = arbitrary_mod_convolution<1LL<<30>(a,b); for (auto &x : c) x %= md; int siz = c.size(); vector d(100); reb(i,100) d[i] = c[siz-1-i]; rep(i,99){ vector e(99-i); rep(j,99-i) e[j] = (d[j]+d[j+1])*(d[j]+d[j+1]) % md; swap(e,d); } out(d[0]); } int main(){ fast_io(); int t = 1; cin >> t; while(t--) solve(); }