#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 100000 + 10;
int t, n, a[N];
ll ans;
int main() {
scanf("%d", &t);
while (t--) {
ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d", a + i);
for (int k = 0; k <= 20; ++k) {
int cnt = 0;
for (int i = 0, v; i < n; ++i) {
v = (a[i] >> k) & 1;
if (v) {
++cnt;
}
else {
ans += (ll)cnt * (cnt + 1) / 2 * (1 << k);
cnt = 0;
}
}
ans += (ll)cnt * (cnt + 1) / 2 * (1 << k);
}
printf("%lld\n", ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTiA9IDEwMDAwMCArIDEwOwppbnQgdCwgbiwgYVtOXTsKbGwgYW5zOwppbnQgbWFpbigpIHsKCXNjYW5mKCIlZCIsICZ0KTsKCXdoaWxlICh0LS0pIHsKCQlhbnMgPSAwOwoJCXNjYW5mKCIlZCIsICZuKTsKCQlmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKCQkJc2NhbmYoIiVkIiwgYSArIGkpOwoJCWZvciAoaW50IGsgPSAwOyBrIDw9IDIwOyArK2spIHsKCQkJaW50IGNudCA9IDA7CgkJCWZvciAoaW50IGkgPSAwLCB2OyBpIDwgbjsgKytpKSB7CgkJCQl2ID0gKGFbaV0gPj4gaykgJiAxOwoJCQkJaWYgKHYpIHsKCQkJCQkrK2NudDsKCQkJCX0KCQkJCWVsc2UgewoJCQkJCWFucyArPSAobGwpY250ICogKGNudCArIDEpIC8gMiAqICgxIDw8IGspOwoJCQkJCWNudCA9IDA7CgkJCQl9CgkJCX0KCQkJYW5zICs9IChsbCljbnQgKiAoY250ICsgMSkgLyAyICogKDEgPDwgayk7CgkJfQoJCXByaW50ZigiJWxsZFxuIiwgYW5zKTsKCX0KCXJldHVybiAwOwp9