#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void bitCount(int *res, int bit[], int length);
void gamingRes(int res, const int *bit, int length, int n);
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int length;
cin >> length;
int res = 0;
int *bit = new int[22];
memset(bit, 0, sizeof(*bit));
bitCount(&res, bit, length);
gamingRes(res, bit, 20, length);
}
return 0;
}
void bitCount(int *res, int bit[], int length) {
for (int j = 0; j < length; j++) {
int x;
cin >> x;
*res ^= x;
int index = 1;
while (x > 0) {
if ((x & 1) > 0) {
bit[index]++;
}
x >>= 1;
index++;
}
}
}
void gamingRes(int res, const int *bit, int length, int n) {
if (res == 0) {
cout << 0 << endl;
} else {
for (int i = length; i > 0; i--) {
if (bit[i] == 1) {
cout << 1 << endl;
break;
}
if ((bit[i] & 1) == 1) {
if ((n & 1) == 1) {
cout << 1 << endl;
break;
} else {
cout << -1 << endl;
break;
}
}
}
}
}
|