#include <bits/stdc++.h>
using namespace std;

#define ll long long int

void solve(){
   ll n,i,j;
   cin >> n;
   ll arr[n];
   ll hash[65] = {0};
   vector<string> vec;
   for(i=0;i<n;i++){
       cin >> arr[i];
       ll m = arr[i];
       ll id = 0;
       string s = "";
       while(m > 0){
           if(m & 1){
               hash[id]++;
               s += "1";
           }
           else
           s += "0";
           id++;
           m/=2;
       }
       vec.push_back(s);
   }
   ll ans[65];ll ps= 0;
   ll bin[65]={0};
   for(i=0;i<65;i++){
       ll a = 1;
       ll p = i;
       while(p > 0){
           p--;
           a *= 2;
            a %= 1000000007;
       }
       bin[i]=a;
       a *= hash[i];
        a %= 1000000007;
        ans[i]=a;
        ps += ans[i];
         ps %= 1000000007;
   }
   /*for(i=0;i<5;i++){
       cout << ans[i] << " fggg " << bin[i] << "\n";
   }*/
   ll s = 0;
 //  cout << ps << '\n';
   for(i=0;i<n;i++){
       ll a = 0;ll b =0;
       string ss = vec[i];
       for(j=0;j<ss.length();j++){
          if(ss[j] == '1'){
              a += ans[j];
               a %= 1000000007;
               b += (bin[j]*(n-hash[j]));
                b %= 1000000007;
          }
       }
       b += ps;
        b %= 1000000007;
        ll ls = (a*b)%1000000007;
        s += ls;
         s %= 1000000007;
        // cout << a << " and or " << b << "\n";
   }
   cout << s << "\n";
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(NULL);
    int t;
    cin >> t;
    while(t > 0){
        t--;
        solve();
    }
}