sum(a[i]|a[j])
//sum((n*n-(n-b[i])^2)*2^i)
#include <iostream>
using namespace std;int main()
{
int b[100];
int a[10010];
int T;
scanf("%d", &T);
while (T--)
{
int n;
scanf("%d", &n);
memset(b, 0, sizeof(b));
int i, max = 0;
int ans = 0;
for (i = 0; i < n; ++i)
{
scanf("%d", &a[i]);
int s = a[i], j;
for (j = 0; s ; j++, s /= 2)
{
if (s % 2)
{
b[j]++;
}
}
if (max < j)
{
max = j;
}
}
for (i = 0; i < max; i++)
{
ans += (n*n-(n-b[i])*(n-b[i])) << i;
}
cout << ans << endl;
}
return 0;
}