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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<=n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define sz(v) ((int)(v).size())
#define get(a,st,en)  fl(i,st,en)       cin>>a[i]
#define pr(a,st,en)     fl(i,st,en)     cout<<a[i]<<" \n"[i==en]

const int MOD = 1e9+7;

void add(long long &a, long long b) {
      a %= MOD;   b %= MOD;
      a = (a + b) % MOD;
}
void mul(long long &a, long long b) {
      a %= MOD;   b %= MOD;
      a = (a * b) % MOD;
}
long long mul2(long long c, int j) {
      long long a = c;
      while(j > 0)  mul(a, 2), j--;
      return a;
}

void solve()    {
      long long n;      cin>>n;
      vector<int> cnt(62, 0);
      vector<long long> arr(n);
      for(auto &i: arr)  {
            cin>>i;
            for(int j=0; j<62; j++) cnt[j] += ((i>>j) & 1);
      }
      vector<long long> pw(62);
      for(int i=0; i<62; i++) pw[i] = mul2(1, i);
      long long ans = 0;
      for(int i=0; i<n; i++)  {
            long long x = 0, y = 0;
            for(int j=0; j<62; j++) {
                  long long b = ((arr[i]>>j) & 1);
                  add(x, (b ? cnt[j]*pw[j] : 0));
                  add(y, (b ? n*pw[j] : cnt[j]*pw[j]));
            }
            mul(x, y);
            add(ans, x);
      }
      cout<<(ans + MOD) % MOD<<"\n";
}
int main()  {
      fast;
      #ifndef ONLINE_JUDGE
      freopen("inputf.in", "r", stdin);
      freopen("outputf.in", "w", stdout);
      #endif
      test()
            solve();
}
// credits @Benq
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

