#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define ld long double
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define endl "\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}
const int N=100005;
vector<bool>prime(N,1);
void sieve(int n) 
{ 
    
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll mod=1e9 + 7;

inline void solve()
{
    ll n;
    cin>>n;
    vll a(n+1);
    rep(i,1,n+1)
    cin>>a[i];
    map<ll,ll>mp;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=60;j++)
        {
            //since 60 bit tak jaayega
            if((1ll<<j)&a[i]) mp[j]++;
        }
    }
    ll res=0;
    rep(i,1,n+1)
    {
        ll ret=0,ret2=0;
        for(int j=0;j<=60;j++)
        {
            //check iss bit ke liye phir satisfy kara
            ll r=1ll<<j;
            ll let_p=(1ll<<j)%mod;
            if(r&a[i])
            {
                //agar wo bit active hua toh ret mein add karde
                ret=(ret + let_p*n)%mod;
                ret2=(ret2 + let_p*mp[j])%mod;
            }
            else
            ret=(ret+let_p*mp[j])%mod;
            //bit set nhi hua toh ret mein kar sirf
        }
        res=(res+ (ret*ret2)%mod)%mod;
    }
    cout<<res<<endl;
}
int main()
{
    Imposter
    
    int t=1;

    cin>>t;
    while(t--)
    {
        solve();
        
    }
    return 0;
}