#include #define int long long using namespace std; using ll = long long; void solve(); template void println(Args... args) { apply([](auto &&... args) { ((cout << args << ' '), ...); }, tuple(args...)); cout << '\n'; } int32_t main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t = 1; cin >> t; for (int tc = 0; tc < t; ++tc) { solve(); } return 0; } int go(vector a, int m) { if (a.size() == 1) return a[0]; vector b(a.size() - 1); for (int i = 0; i + 1 < a.size(); ++i) b[i] = a[i] + a[i + 1]; for (int &x : b) x *= x; for (int &x : b) x %= (1LL << m); return go(b, m); } void solve() { int n, m; cin >> n >> m; vector a(n); for (int &x : a) cin >> x; if (a.size() <= m) return println(go(a, m)); auto binom = [&](int n, int k) { for (int bit = 0; (1 << bit) <= n; ++bit) { if (((n & (1 << bit)) == 0) && ((k & (1 << bit)))) return 0; } return 1; }; vector b(m); for (int i = 0; i < m; ++i) { for (int j = 0; j + m <= n; ++j) { b[i] += binom(n - m + 1, j) * a[i + j]; b[i] %= 2; } } cout << go(b, m) << '\n'; }