#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int singificant_bit_position(int x)
{
    int pos = 0;
    while (x != 0)
    {
        x /= 2;
        ++pos;
    }
    return pos;
}

void mainSolve()
{
    int n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    unordered_map<ll, ll> m;
    for (int x : v)
        ++m[singificant_bit_position(x)];

    ll ans = 0;
    for (auto it : m)
    {
        ans = (ans + (it.second * (it.second - 1ll)) / 2ll);
    }
    cout << ans << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        mainSolve();
    }
    return 0;
}