#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MEM(a,b) memset((a),(b),sizeof(a)) const LL INF = 1e9 + 7; const int N = 2e5 + 10; LL a[N]; LL powmod(LL a, LL b, LL mod) { LL ret = 1; while (b) { if (b & 1) ret = ret * a % mod; b >>= 1; a = a * a % mod; } return ret; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int ncase; scanf("%d", &ncase); while (ncase--) { int n, m; scanf("%d%d", &n, &m); m = 1 << m; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); if (n <= 100) { while (n > 1) { for (int i = 1; i < n; i++) { a[i] = (a[i] + a[i + 1]) * (a[i] + a[i + 1]) % m; } n--; } printf("%lld\n", a[1]); } else { LL ans = 0; for (int i = 1; i <= n; i++) { ans += powmod(a[i], m / 2, m); } printf("%lld\n", ans % m); } } return 0; }