#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  for (int i1 = 0; i1 < t; ++i1) {
    int n;
    cin >> n;
    vector<int> t0(64), t1(64);
    vector<long long> val(n + 1);
    vector<long long> val1(n + 1);
    vector<long long> wei(64);
    for (int i = 0; i < n; ++i) {
      long long f;
      cin >> f;
      val[i + 1] = f;
      int cnt = 0;
      for (int j = 0; j < 62; j++) {
        if (f & 1)
          t1[cnt]++;
        else
          t0[cnt]++;
        cnt++;
        f /= 2;
      }
    }
    for (int i = 1; i <= n; ++i) {
      long long f = val[i];
      long long ans = 0;
      int cnt = 0;
      long long bs = 1;
      for (int j = 0; j < 62; j++) {
        if (f & 1)
          ans = (ans + (t0[j] + t1[j]) * bs % mod) % mod;
        else
          ans = (ans + t1[j] * bs % mod) % mod;
        f /= 2;
        bs = bs * 2 % mod;
      }
      val1[i] = ans;
    }
    for (int i = 0; i < 62; ++i) {
      for (int j = 1; j <= n; ++j) {
        if ((val[j] & (1ll << i)) != 0) {
          wei[i] = (wei[i] + val1[j]) % mod;
        }
      }
    }
    long long ans = 0;
    long long bs = 1;
    for (int i = 0; i < 62; ++i) {
      long long qian = t1[i] * bs % mod;
      ans = (ans + (long long)qian * wei[i] % mod) % mod;
      bs *= 2;
      bs %= mod;
    }
    cout << ans << '\n';
  }
  return 0;
}
