#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <unordered_map>
#include <queue>
#include <map>
#include <sstream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <unordered_set>
#include <bitset>
#include <fstream>
#include <chrono>
using namespace std;
typedef long long ll;
#pragma GCC optimize(3, "Ofast", "inline")
#define fir(i, a, b) for (int i = a; i <= b; i++)
#define mov(i) (1ll << i)
#define MAX_INF 0x3f3f3f3f
const int mod = 1e9 + 7;
struct ios
{
    inline char read()
    {
        static const int IN_LEN = 1e6 + 10;
        static char buf[IN_LEN], *s, *t;
        return (s == t) && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)), s == t ? -1 : *s++;
    }
    template <typename _Tp>
    inline ios &operator>>(_Tp &x)
    {
        static char c11, boo;
        for (c11 = read(), boo = 0; !isdigit(c11); c11 = read())
        {
            if (c11 == -1)
                return *this;
            boo |= c11 == '-';
        }
        for (x = 0; isdigit(c11); c11 = read())
            x = x * 10 + (c11 ^ '0');
        boo && (x = -x);
        return *this;
    }
} io;
namespace IO
{
    template <typename T>
    inline void w(T x)
    {
        if (x > 9)
            w(x / 10);
        putchar(x % 10 + 48);
    }
    template <typename T>
    inline void write(T x, char c)
    {
        if (x < 0)
            putchar('-'), x = -x;
        w(x);
        putchar(c);
    }
    template <typename T>
    inline void read(T &x)
    {
        x = 0;
        T f = 1;
        char c = getchar();
        for (; !isdigit(c); c = getchar())
            if (c == '-')
                f = -1;
        for (; isdigit(c); c = getchar())
            x = (x << 1) + (x << 3) + (c ^ 48);
        x *= f;
    }
} // namespace IO
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll qpow(ll a, ll b, ll p)
{

    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return ans;
}
void input()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
}
const int maxn=5e5+10;
ll a[maxn];
ll cnt[100];
ll now[100];
int main()
{
 //   input();
    int T;
    io>>T;
    fir(i,0,60)
    now[i]=mov(i)%mod;
    while(T--)
    {
        ll ans=0;
        int n;
        io>>n;
        fir(i,1,n)io>>a[i];
        fir(i,0,70)cnt[i]=0;
        fir(i,1,n)
        {
            ll &x=a[i];
            for(int j=0;j<=60;j++)
            if((x>>j)&1)cnt[j]++;
        }
        fir(i,1,n)
        {
            ll ans1=0,ans2=0;
            ll & x=a[i];
            fir(j,0,60)
            {
                if((x>>j)&1)
                {
                    ans1=(ans1+now[j]*cnt[j])%mod;
                    ans2=(ans2+now[j]*n)%mod;
                }
                else ans2=(ans2+now[j]*cnt[j])%mod;
            }
            ans=(ans+ans1*ans2)%mod;
        }
        IO::write(ans,'\n');
    }
}