#include<stdio.h>

#include<string.h>

int main(){

```
int t,n,k,ans,i,sum;
int *a;
char *op=(char*)malloc(4);
scanf("%d",&t);
while(t-- >0){
scanf("%d %d %d",&n,&k,&ans);
a=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++){
scanf("%d",a+i);
}
scanf("%s",op);
if(strcmp(op,"XOR")==0){
sum=a[0];
for(i=1;i<n;i++)
sum=sum^a[i];
if(k%2!=0)
printf("%d\n",ans^sum);
else
printf("%d\n",ans^0);
}
else if(strcmp(op,"AND")==0){
sum=a[0];
for(i=1;i<n;i++)
sum=sum & a[i];
printf("%d\n",ans & sum);
}
else{
sum=a[0];
for(i=1;i<n;i++)
sum=sum | a[i];
printf("%d\n",ans | sum);
}
}
//getch();
return 0;
```

}

//here is the link to the problem :http://www.codechef.com/problems/RRCODE/