// Cheese-Cracker: cheese-cracker.github.io

const ll PRIME = 10^^9 + 7L;

void theCode(){
    int n;
    n = scan!int;
    auto arr = scanArray;
    ll summ = 0;
    foreach(el; arr){ summ += el; summ %= PRIME; }
    auto freq = new ll[61];
    foreach(el; arr){
        for(int s = 0; s <= 60; ++s){
            ll mask = 1L<<s;
            if(mask & el) ++freq[s];
        }
    }
    ll res = 0;
    foreach(el; arr){
        ll andsum = 0;
        for(int s = 0; s <= 60; ++s){
            ll val = 1L<<s;
            if(val & el){
                val %= PRIME;
                andsum += val * freq[s];
                andsum %= PRIME;
            }
        }
        ll cursum = summ + n.to!long * (el % PRIME);
        cursum %= PRIME;
        ll term = (cursum - andsum + PRIME) % PRIME;
        res += andsum * term;
        res %= PRIME;
    }
    writeln(res);
}

void main(){
    long tests = 1;
    tests = scan;        // Toggle!
    while(tests--) theCode();
}

/*********  That's All Folks!  *********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] tk;
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");
