/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/

#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
int dx[]={-1, 0, 0, 1};
int dy[]={0, -1, 1, 0};
int dx1[]={-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy1[]={-1, 0, 1, -1, 0, 1, -1, 0, 1};

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll t, z=0;
    cin>>t;
    while(t--){
        ll n, m, k, i, j, x, y, p=0, s=0, h, f=0, ans=0;
        cin>>n;
        ll a[n];
        ll bit[64];
        mem(bit, 0);
        for(i=0; i<n; i++){
            cin>>a[i];
        }
        for(i=0; i<63; i++){
            for(j=0; j<n; j++){
                k = 1LL<<i;
                if((a[j]&k)!=0){
                    bit[i]++;
                }
            }
        }
        for(i=0; i<n; i++){
            x=0, y=0;
            for(j=0; j<63; j++){
                k = 1LL<<j;
                if((a[i]&k)!=0){
                    x =((((k%md)*(bit[j]%md))%md) +x)%md;
                }
            }
            for(j=0; j<63; j++){
                k = 1LL<<j;
                if((a[i]&k)==0){
                    y =((((k%md)*(bit[j]%md))%md) +y)%md;
                }
                else{
                    y =((((k%md)*(n%md))%md) +y)%md;
                }
            }
            ans = ((ans%md)+((x%md)*(y%md))%md)%md;
        }
        cout<<ans<<endl;
    }
    return 0;
}

