#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } int naive(vector a, int m){ int n = a.size(); for(int i = 0; i < n-1; i++){ vector b(a.size()-1); for(int j = 0; j+1 < a.size(); j++){ ll sum = a[j]+a[j+1]; b[j] = (sum*sum)%(1< add(vector a, vector b){ int n = a.size(); vector ans(n); for(int i = 0; i < n; i++) ans[i] = a[i]+b[i]; return ans; } void calc(int n, int m){ map, ll> mp; mp[{1}] = 1; for(int i = 0; i < n; i++){ map, ll> nx; auto add_mp = [&](vector ww, ll s){ if(nx.count(ww)) { nx[ww] += s%(1< uu = {0}; for(int a: u) uu.push_back(a); auto ww = add(uu, vv); add_mp(ww, x*y*2); } for(auto [u, y]: mp){ auto vv = v; vv.push_back(0); auto uu = u; uu.push_back(0); auto ww = add(uu, vv); add_mp(ww, x*y); } for(auto [u, y]: mp){ vector vv = {0}; for(int a: v) vv.push_back(a); vector uu = {0}; for(int a: u) uu.push_back(a); auto ww = add(uu, vv); add_mp(ww, x*y); } } mp.clear(); for(auto [v, x]: nx){ if(x == 0) continue; mp[v] = x; } } for(auto [u, x]: mp){ for(int y: u) cout << y << ' '; cout << ":" << x << endl; } } void test(int n, int m){ for(int s = 0; s < (1< a(n); for(int i = 0; i < n; i++){ if(s&(1<> n >> m; vector a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } int M = 31; if(n <= 31){ cout << naive(a, m) << endl; return; } vector b(31); int len = n-31; for(int l = 0; l < 31; l++){ for(int i = l; i <= l+len; i++){ if(a[i]%2 == 0) continue; if(is_nCk_odd(len, i-l)) b[l] ^= 1; } } cout << naive(a, m) << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }