#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 1048576;
long long solve(vector<int> &contain)
{
long long ans = 0;
for (int j = 0; (1<<j) < MAXN; j++) {
for (int i = 0; i < MAXN; i++) if (!(i & (1<<j))) {
contain[i] += contain[i^(1<<j)];
}
}
for (int i = 0; i < MAXN; i++) {
if (__builtin_popcount(i) & 1) ans -= (contain[i]*1ll*(contain[i]-1));
else ans += (contain[i]*1ll*(contain[i]-1));
}
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",contain[0]+solve(contain));
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
tmain();
return 0;
}
ICAgICNpbmNsdWRlIDxjc3RkaW8+CiAgICAjaW5jbHVkZSA8dmVjdG9yPgogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAgICAKICAgIGNvbnN0IGludCBNQVhOID0gMTA0ODU3NjsKICAgIGxvbmcgbG9uZyBzb2x2ZSh2ZWN0b3I8aW50PiAmY29udGFpbikKICAgIHsKICAgIAlsb25nIGxvbmcgYW5zID0gMDsKICAgIAlmb3IgKGludCBqID0gMDsgKDE8PGopIDwgTUFYTjsgaisrKSB7CiAgICAJCWZvciAoaW50IGkgPSAwOyBpIDwgTUFYTjsgaSsrKSBpZiAoIShpICYgKDE8PGopKSkgewogICAgCQkJY29udGFpbltpXSArPSBjb250YWluW2leKDE8PGopXTsKICAgIAkJfQogICAgCX0KICAgIAlmb3IgKGludCBpID0gMDsgaSA8IE1BWE47IGkrKykgewogICAgCQlpZiAoX19idWlsdGluX3BvcGNvdW50KGkpICYgMSkgYW5zIC09IChjb250YWluW2ldKjFsbCooY29udGFpbltpXS0xKSk7CiAgICAJCWVsc2UgYW5zICs9IChjb250YWluW2ldKjFsbCooY29udGFpbltpXS0xKSk7CiAgICAJfQogICAgCXJldHVybiBhbnM7CiAgICB9CiAgICB2b2lkIHRtYWluKCkKICAgIHsKICAgIAlpbnQgTjsKICAgIAl2ZWN0b3I8aW50PiBjb250YWluKE1BWE4pOwogICAgCXNjYW5mKCIlZCIsJk4pOwogICAgCWZvcihpbnQgaT0wO2k8TjtpKyspCiAgICAJewogICAgCQlpbnQgdDsKICAgIAkJc2NhbmYoIiVkIiwmdCk7CiAgICAJCWNvbnRhaW5bdF0rKzsKICAgIAl9CgogICAgCXByaW50ZigiJWxsZFxuIixjb250YWluWzBdK3NvbHZlKGNvbnRhaW4pKTsKICAgIH0KICAgIGludCBtYWluKCkKICAgIHsKICAgIAlpbnQgVDsKICAgIAlzY2FuZigiJWQiLCZUKTsKICAgIAl3aGlsZShULS0pCiAgICAJCXRtYWluKCk7CiAgICAJcmV0dXJuIDA7CiAgICB9