#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 1048576;
long long solve(vector<int> &contain)
{
if(contain.size()==1)
return 1LL*contain[0]*contain[0];
vector<int> halved(contain.size()/2);
for(int i=0;i<contain.size()/2;i++)
halved[i]=contain[i+contain.size()/2];
long long ans = -solve(halved);
for(int i=0;i<contain.size()/2;i++)
halved[i]+=contain[i];
ans+=solve(halved);
return ans;
}
void tmain()
{
int N;
vector<int> contain(MAXN);
scanf("%d",&N);
for(int i=0;i<N;i++)
{
int t;
scanf("%d",&t);
contain[t]++;
}
printf("%lld\n",solve(contain));
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
tmain();
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhOID0gMTA0ODU3NjsKbG9uZyBsb25nIHNvbHZlKHZlY3RvcjxpbnQ+ICZjb250YWluKQp7CglpZihjb250YWluLnNpemUoKT09MSkKCQlyZXR1cm4gMUxMKmNvbnRhaW5bMF0qY29udGFpblswXTsKCQoJdmVjdG9yPGludD4gaGFsdmVkKGNvbnRhaW4uc2l6ZSgpLzIpOwoJZm9yKGludCBpPTA7aTxjb250YWluLnNpemUoKS8yO2krKykKCQloYWx2ZWRbaV09Y29udGFpbltpK2NvbnRhaW4uc2l6ZSgpLzJdOwoJbG9uZyBsb25nIGFucyA9IC1zb2x2ZShoYWx2ZWQpOwoJCglmb3IoaW50IGk9MDtpPGNvbnRhaW4uc2l6ZSgpLzI7aSsrKQoJCWhhbHZlZFtpXSs9Y29udGFpbltpXTsKCWFucys9c29sdmUoaGFsdmVkKTsKCQoJcmV0dXJuIGFuczsKfQp2b2lkIHRtYWluKCkKewoJaW50IE47Cgl2ZWN0b3I8aW50PiBjb250YWluKE1BWE4pOwoJc2NhbmYoIiVkIiwmTik7Cglmb3IoaW50IGk9MDtpPE47aSsrKQoJewoJCWludCB0OwoJCXNjYW5mKCIlZCIsJnQpOwoJCWNvbnRhaW5bdF0rKzsKCX0KCXByaW50ZigiJWxsZFxuIixzb2x2ZShjb250YWluKSk7Cn0KaW50IG1haW4oKQp7CglpbnQgVDsKCXNjYW5mKCIlZCIsJlQpOwoJd2hpbGUoVC0tKQoJCXRtYWluKCk7CglyZXR1cm4gMDsKfQ==