#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define print(a) for(auto x : a) cout << x << " "; cout << endl
const int M = 1000000007;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;
inline int power(int a, int b, int mod=M) {
int x = 1;
a %= mod;
while (b) {
if (b & 1) x = (x * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return x;
}
//_ ***************************** START Below *******************************
const int N = 3e6+9;
vector<int> a;
int consistency1(int n){
int ct = 0;
for(int i=0; i<=n-4; i++){
for(int j=i+1; j<=n-3; j++){
unordered_map<int,int> mp;
for(int k=n-1; k>=j+2; k--){
mp[a[k]]++;
}
for(int k=j+1; k<=n-2; k++){
int xr = a[i] ^ a[j] ^ a[k];
ct += mp[xr];
mp[a[k+1]]--;
if(mp[a[k+1]] == 0) mp.erase(a[k]);
}
}
}
return ct * 24;
}
int consistency2(int n){
unordered_map<int,int> mp;
for(int k=2; k<=n-2; k++){
for(int l=k+1; l<=n-1; l++){
int xr = a[k] ^ a[l];
mp[xr]++;
}
}
int ct = 0;
for(int j=1; j<=n-3; j++){
for(int i=j-1; i>=0; i--){
int xr = a[i] ^ a[j];
ct += mp[xr];
}
for(int k=j+2; k<n; k++){
int xr = a[j+1] ^ a[k];
mp[xr]--;
if(mp[xr] == 0) mp.erase(xr);
}
}
return ct * 24;
}
//* Optimize Unordered map with vector :
int consistency3(int n){
vector<int> mp(N, 0);
for(int k=2; k<=n-2; k++){
for(int l=k+1; l<=n-1; l++){
int xr = a[k] ^ a[l];
mp[xr]++;
}
}
int ct = 0;
for(int j=1; j<=n-3; j++){
for(int i=j-1; i>=0; i--){
int xr = a[i] ^ a[j];
ct += mp[xr];
}
for(int k=j+2; k<n; k++){
int xr = a[j+1] ^ a[k];
mp[xr]--;
}
}
return ct * 24;
}
int practice(int n){
return 0;
}
void solve() {
int n;
cin>> n;
a.resize(n);
for(int i=0; i<n; i++) cin >> a[i];
cout << consistency3(n) << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}