#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> s(n);
        unordered_map<int, int> mp;
        int ans = 0;
        unordered_map<int, int> res1, res2;
        for (int i = 0; i < n; ++i) {
            long long x;
            cin >> x;
            s[i] = x;
            for (int j = 0; j < 60; ++j) {
                mp[j] += (((s[i] >> j) & 1LL));
                mp[j] %= MOD;
            }
        }
        long long res = 0;
        for (int i = 0; i < n; ++i) {
            long long ANDD = 0LL;
            long long ORR = 0LL;
            for (int j = 0; j < 60; ++j) {
                if (((s[i] >> j) & 1LL)) {
                    ORR += (n * ((1LL << j) % MOD)) % MOD;
                    ANDD += ((mp[j] % MOD) * ((1LL << j) % MOD)) % MOD;
                } else {
                    ORR += ((mp[j] % MOD) * ((1LL << j) % MOD)) % MOD;
                    ANDD += 0LL;
                }
                ORR %= MOD;
                ANDD %= MOD;
            }
            res += (ORR * ANDD) % MOD;
            res %= MOD;
        }
        cout << res << "\n";
    }
}
