#include <bits/stdc++.h>
 // codeforces.com/gym/101532/problem/A
using namespace std;
const int N = 1e5 + 6;
int n;
int arr[N];
// value & (1 << bit)
int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> arr[i];
        }
        long long ans = 0;
        for (int bit = 0; bit < 32; ++bit) {
            long long c = 0, number_of_subs = 0;
            for (int i = 0; i < n; ++i) {
                if (arr[i] & (1 << bit)) {
                    c++;
                } else {
                    number_of_subs += c * (c + 1) / 2;
                    c = 0;
                }
            }
            number_of_subs += c * (c + 1) / 2;
            ans += number_of_subs * (1LL << bit);
        }
        cout << ans << endl;
    }
 
    return 0;
}