/// You just can't beat the person who never gives up
/// ICPC next year

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

const int N = 5e5+5 ,mod = 1e9+7 ;

int t ,n ;
long long a[N] ,ans_or[N] ,cnt[60] ;
vector<int> idx[60] ;
int main(){
    scanf("%d",&t);
    while(t--){
        for(int i=0;i<60;++i) idx[i].clear();
        memset(cnt,0,sizeof cnt);
        scanf("%d",&n);
        for(int i=0;i<n;++i){
            scanf("%lld",a+i);
            for(int j=59;j>=0;--j) if(a[i]>>j&1){
                idx[j].push_back(i);
                ++cnt[j] ;
            }
        }
        for(int i=0;i<n;++i){
            ans_or[i] = 0 ;
            for(int j=59;j>=0;--j){
                if(a[i]>>j&1){
                    long long cur = (1ll<<(1ll*j))%mod ;
                    cur = (1ll*cur*n)%mod ;
                    ans_or[i] = (cur+ans_or[i])%mod ;
                }
                else{
                    long long cur = (1ll<<(1ll*j))%mod ;
                    cur = (1ll*cur*cnt[j])%mod ;
                    ans_or[i] = (cur+ans_or[i])%mod ;
                }
            }
        }
        long long ans = 0 ;
        for(int j=59;j>=0;--j){
            for(int i=0;i<idx[j].size();++i){
                long long cur = (1ll<<(1ll*j))%mod ;
                cur = 1ll*cur*idx[j].size()%mod ;
                cur = 1ll*cur*ans_or[idx[j][i]]%mod;
                ans = (ans + cur)%mod ;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}
