#include <bits/stdc++.h>
using namespace std;
long long n,k,t,a[200010],b[200010]={};
int main(){
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>k;
memset(b,0,sizeof(b));
for(int j=1;j<=n;j++){
cin>>a[j];
}
if(n%2){
for(int j=1;j<=n;j++){
for(int q=1;q<=n;q++){
if(q!=j){
b[j]=b[j]^a[q];
}
}
}
for(int j=1;j<=n;j++){
cout<<b[j]<<" ";
}
cout<<endl;
}
else{
if(k%2){
for(int j=1;j<=n;j++){
for(int q=1;q<=n;q++){
if(q!=j){
b[j]=b[j]^a[q];
}
}
}
for(int j=1;j<=n;j++){
cout<<b[j]<<" ";
}
cout<<endl;
}
else{
for(int j=1;j<=n;j++){
cout<<a[j]<<" ";
}
cout<<endl;
}
}
}
return 0;
}