//in the name of GOD
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define ll long long int
#define mpp make_pair
#define pii pair<ll,ll>
#define pb push_back

const int MD=1e9+7;
ll pow2[70];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    pow2[0]=1;
    for(int i=1;i<65;i++){
        pow2[i]=(pow2[i-1]*2)%MD;
        pow2[i]=(pow2[i]+MD)%MD;
    }
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll a[n+1];
        for(int i=0;i<n;i++) cin>>a[i];
        int bit[70];
        fill(bit,bit+70,0);
        for(int i=0;i<n;i++){
            ll k=a[i];
            int j=0;
            while(k>0){
                if(k%2==1) bit[j]++;
                j++;
                k/=2;
            }
        }
        ll ans=0;
        for(int i=0;i<n;i++){
            bool b[70];
            fill(b,b+70,0);
            ll k=a[i];
            int j=0;
            while(k>0){
                if(k%2==1) b[j]=1;
                j++;
                k/=2;
            }
            ll andi=0;
            for(int i=0;i<60;i++){
                if(b[i]==1){
                    andi+=(bit[i]*pow2[i])%MD;
                    andi=(andi+MD)%MD;
                }
            }
            ll ori=0;
            for(int i=0;i<60;i++){
                if(b[i]==1){
                    ori+=(n*pow2[i])%MD;
                    ori=(ori+MD)%MD;
                }
                else{
                    ori+=(bit[i]*pow2[i]%MD);
                    ori=(ori+MD)%MD;
                }
            }
            ll ppp=(andi*ori)%MD;
            ppp=(ppp+MD)%MD;
            ans=(ans+ppp)%MD;
            ans=(ans+MD)%MD;
        }
        cout<<ans<<endl;
    }
    return 0;
}
