import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
static int maxn = 200005;
static boolean isodd(long a, long b) {
if((a&b)==b) return true;
else return false;
}
public static void main(String[] args)
{
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
for(int i = 1; i <= t; i ++) {
int a[] = new int [maxn];
int b[] = new int [maxn];
int n = in.nextInt();
long m = in.nextLong();
for(int j = 1; j <= n; j ++) {
a[j] = in.nextInt();
}
for(int j = n; j >= 1; j --)
{
if(isodd(n + m - 1 - j, m - 1))
{
for(int k = n; k >= n - j + 1; k --)
{
b[k]^=a[k + j - n];
}
}
}
for(int k = 1; k <= n; k ++) {
if(k == 1) {
out.print(b[k]);
}
else out.print(" "+ b[k]);
}
out.println();
}
out.close();
}
}
class InputReader
{
BufferedReader buf;
StringTokenizer tok;
InputReader()
{
buf = new BufferedReader(new InputStreamReader(System.in));
}
boolean hasNext()
{
while(tok == null || !tok.hasMoreElements())
{
try
{
tok = new StringTokenizer(buf.readLine());
}
catch(Exception e)
{
return false;
}
}
return true;
}
String next()
{
if(hasNext()) return tok.nextToken();
return null;
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
BigInteger nextBigInteger()
{
return new BigInteger(next());
}
BigDecimal nextBigDecimal()
{
return new BigDecimal(next());
}
}