#include using namespace std; namespace std { template istream& operator>>(istream& is, pair& p) { return is >> p.first >> p.second; } template istream& operator>>(istream& is, tuple& t) { return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } template istream& operator>>(istream& is, tuple&& t) { return is >> t; } template >* = nullptr> auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) { for (auto&& e : r) { is >> e; } return is; } template ostream& operator<<(ostream& os, const pair& p) { return os << p.first << ' ' << p.second; } template ostream& operator<<(ostream& os, const tuple& t) { auto f = [&os](const auto&... xs) -> ostream& { [[maybe_unused]] auto sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } template >* = nullptr> auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) { auto sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << e; } return os; } } // namespace std // end library namespace std::ranges::views { namespace { using ::move; void solve() { int n, m; cin >> n >> m; vector a(n); cin >> a; if (m < n) { vector na(m); for (int i : iota(0, m)) { for (int j : iota(0, n - m + 1)) { if ((j & ~(n - m)) == 0) { na[i] += a[i + j]; } } } } while (1 < a.size()) { vector na(a.size() - 1); for (int i : iota(0, int(na.size()))) { na[i] = a[i] + a[i + 1]; na[i] *= na[i]; } a = move(na); } cout << (a[0] & ~(-1 << m)) << '\n'; } } // namespace } // namespace std::ranges::views using views::solve; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } }