#include <bits/stdc++.h>

using namespace std;
#define LL long long
#define PB push_back
#define double long double
const double eps=1e-10,MAXN=1e18;
const int N=6e5+10,mod=1e9+7;
int n,q;
LL a[N];
LL s[N];
void solve(){
    scanf("%d",&n);
    for(int i=0;i<61;i++)s[i]=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        for(int j=0;j<61;j++)if((a[i]>>j)&1)s[j]++;
    }
    LL ans=0;
    for(int i=1;i<=n;i++){
        //cout<<i<<endl;
        LL sum=0;
        for(int j=0;j<61;j++){
            if((a[i]>>j)&1)sum+=(1ll<<j)%mod*n%mod;
        else
            sum+=(1ll<<j)%mod*s[j]%mod;
            sum%=mod;
        }
    //cout<<i<<endl;
        for(int j=0;j<61;j++){
            if((a[i]>>j)&1){
                ans+=(1ll<<j)%mod*s[j]%mod*sum%mod;
                //cout<<i<<' '<<j<<' '<<ans<<' '<<sum<<' '<<(1ll<<j)<<' '<<s[j]<<endl;
            }
            ans%=mod;

        }
        //cout<<i<<' '<<ans<<endl;
    }
    printf("%lld\n",ans);
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
/*
2
0 1
1 1
1 0
0 1

3
1 0 0
0 1 0
0 0 1
1 1 1
1 1 1
1 1 1

*/
