import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int mod = 10 ^^ 9 + 7;
immutable int limit = 60;
immutable auto p2 = limit.iota.map !(i => (1L << i) % mod).array.idup;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(long)).array;

		auto c = new int [limit];
		foreach (j; 0..n)
		{
			foreach (d; 0..limit)
			{
				if ((a[j] >> d) & 1)
				{
					c[d] += 1;
				}
			}
		}

		int res = 0;
		foreach (j; 0..n)
		{
			int lo = 0;
			int hi = 0;
			foreach (d; 0..limit)
			{
				if ((a[j] >> d) & 1)
				{
					lo = (lo + p2[d] * 1L * c[d]) % mod;
					hi = (hi + p2[d] * 1L * n) % mod;
				}
				else
				{
					lo = (lo + p2[d] * 1L * 0) % mod;
					hi = (hi + p2[d] * 1L * c[d]) % mod;
				}
			}
			res = (res + lo * 1L * hi) % mod;
		}
		writeln (res);
	}
}
