                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        int n,cnt;

                        bool p[INF*10+20];
                    int main()
                    {
                        cin>>n;
                        memset(p,true,sizeof(p));
                        p[1]=false;
                        for (int i=2;i*i<=INF+10;i++)
                        {
                            if (!p[i]) continue;
                            for (int j=i*i;j<=INF+10;j+=i)
                            {
                                p[j]=false;
                            }
                        }

                        for (int i=2;i<=INF*10;i++)
                        {
                            if (p[i]) {cout<<i<<' ';cnt++;}
                            if (cnt==n) break;
                        }

                        //system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        ll n,cnt;

                        bool p[INF*10+20];
                    int main()
                    {
                        cin>>n;
                        //memset(p,true,sizeof(p));

                        p[1]=true;
                        for (int i=2;i*i<INF*10+10;i++)
                        {
                            if (p[i]) continue;

                            for (int j=i*i;j<INF*10+10;j+=i)
                            {
                                p[j]=true;
                            }
                        }

                        for (int i=2;i<=INF*10+5;i++)
                        {
                            if (!p[i]) {cout<<i<<' ';cnt++;}
                            if (cnt==n) break;
                        }

                       // system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        int n,cnt;

                        bool p(int x)
                        {
                             if (x<2) return false;

                             for (int i=2;i<=sqrt(x);i++)
                             {
                                 if (x%i==0) return false;
                             }
                             return true;
                        }
                    int main()
                    {
                        cin>>n;
                        for (int i=2;i<=INF*10;i++)
                        {
                            if (p(i)) {cout<<i<<' ';cnt++;}
                            if (cnt==n) break;
                        }

                      //  system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        ll n,cnt;

                        bool p[INF*10+20];
                    int main()
                    {
                        cin>>n;
                        //memset(p,true,sizeof(p));

                        p[1]=true;
                        for (int i=2;i*i<INF+10;i++)
                        {
                            if (p[i]) continue;

                            for (int j=i*i;j<INF+10;j+=i)
                            {
                                p[j]=true;
                            }
                        }

                        for (int i=2;i<=INF*10;i++)
                        {
                            if (!p[i]) {cout<<i<<' ';cnt++;}
                            if (cnt==n) break;
                        }

                       // system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <bits/stdc++.h>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        int n,cnt;

                        bool p[INF*10+20];
                    int main()
                    {
                        cin>>n;
                        memset(p,true,sizeof(p));
                        p[1]=false;
                        for (int i=2;i*i<=INF+10;i++)
                        {
                            if (!p[i]) continue;
                            for (int j=i*i;j<=INF+10;j+=i)
                            {
                                p[j]=false;
                            }
                        }

                        for (int i=2;i<=INF*10;i++)
                        {
                            if (p[i]) {cout<<i<<' ';cnt++;}
                            if (cnt==n) break;
                        }

                       // system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        int n,cnt;

                        bool p[INF*10+20];
                    int main()
                    {
                        cin>>n;
                        memset(p,true,sizeof(p));
                        p[1]=false;
                        for (int i=2;i*i<=INF+10;i++)
                        {
                            if (!p[i]) continue;
                            for (int j=i*i;j<=INF+10;j+=i)
                            {
                                p[j]=false;
                            }
                        }

                        for (int i=2;i<=INF*10;i++)
                        {
                            if (p[i]) {cout<<i<<' ';cnt++;}
                            if (cnt==n) break;
                        }

                       // system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        int n,cnt,i=1;
                        map <ll,ll> a;
                    int main()
                    {
                        cin>>n;

                        a[1]=1;
                        for (int i=2;i<=INF*10;i++)
                        {
                             if (a[i]==0)
                             {
                                for (int j=i*i;j<=INF*10;j+=i)
                                {
                                    a[j]=1;
                                }
                             }
                        }
                        while (cnt<n)
                        {
                             if (a[i]==0) {cout<<i<<' ';cnt++;}
                             i++;
                        }

                      //  system("pause");
                        r0;
                    }


                    #include <iostream>
                    #include <cstdlib>
                    #include <cstdio>
                    #include <map>
                    #include <cmath>
                    #include <algorithm>
                    #define MX +100500
                    #define ll long long
                    #define uns unsigned
                    #define r0 return 0;
                    #define INF 1000000
                    #define sf scanf
                    #define pf printf
                    #define itr ::iterator
                    #define pb push_back
                    #define mp make_pair
                    #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                    #define all(x) x.begin(),x.end()
                    #define f first
                    #define s second
                    using namespace std;

                        int n,cnt;

                        bool p(int x)
                        {
                             if (x<2) return false;

                             for (int i=2;i<=sqrt(x);i++)
                             {
                                 if (x%i==0) return false;
                             }
                             return true;
                        }
                    int main()
                    {
                        sf("%d",&n);
                        for (int i=2;i<=INF*10;i++)
                        {
                            if (p(i)) {pf("%d ",i);cnt++;}
                            if (cnt==n) break;
                        }

                      //  system("pause");
                        r0;
                    }


#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <queue>

int main() {
    int n; std::cin >> n;
    int64_t prev = 3;
    std::cout << prev;
    for (int i = 2; i <= n; ++i) {
        int64_t curr = prev*i+1;
        std::cout << ' ' << curr;
        prev = curr;
    }
    std::cout << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <queue>

std::vector<int> primes;

void seive(int n) {
    std::vector<bool> composite(n+1);
    composite[0] = composite[1] = true;
    for (int i = 1; i <= n; ++i) {
        if (!composite[i]) {
            primes.push_back(i);
            for (int j = i+i; j <= n; j += i) {
                composite[j] = true;
            }
        }
    }
}

int main() {
    seive(10000000);
    int n; std::cin >> n;
    for (int i = 0; i < n; ++i) {
        if (i > 0) std::cout << ' ';
        std::cout << primes[i];
    }
    std::cout << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <queue>

int main() {
    int n; std::cin >> n;
    int64_t prev = 3;
    std::cout << prev;
    for (int i = 2; i <= n; ++i) {
        int64_t curr = prev*2+1;
        std::cout << ' ' << curr;
        prev = curr;
    }
    std::cout << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <queue>

std::vector<int> primes;

void seive(int n) {
    std::vector<bool> composite(n+1);
    composite[0] = composite[1] = true;
    for (int i = 1; i <= n; ++i) {
        if (!composite[i]) {
            primes.push_back(i);
            for (int j = i+i; j <= n; j += i) {
                composite[j] = true;
            }
        }
    }
}

int main() {
    seive(10000000);
    int n; std::cin >> n;
    std::cout << primes.size() << '\n';
    for (int i = 0; i < n; ++i) {
        if (i > 0) std::cout << ' ';
        std::cout << primes[i];
    }
    std::cout << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    if(n==1)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    int temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
string al="abcdefghijklmnopqrstuvwxyz";
pair<ll,ll>p[20000];
unordered_map <char,ll> mapp;
unordered_map <char,ll> mapp1;
vector<ll>vi;
vector<ll>vi1;
vector<ll>vi2;
ll n,sum,l,r,x,a[2000000],ma=-999999999999999999,i,cnt;
string s,t;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(i=2;i<=1000000000000;i++){
        if(isPrime(i)){
            printf("%d ",i);
            cnt++;
        }
        if(cnt==n){
            return 0;
        }
    }
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    if(n==1)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    int temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
string al="abcdefghijklmnopqrstuvwxyz";
pair<ll,ll>p[20000];
unordered_map <char,ll> mapp;
unordered_map <char,ll> mapp1;
vector<ll>vi;
vector<ll>vi1;
vector<ll>vi2;
ll n,sum,l,r,x,a[2000000],ma=-999999999999999999,i,cnt;
string s,t;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(i=1;i<=100000000000000000;i++){
        if(isPrime(i)){
            cout<<i<<" ";
            cnt++;
        }
        if(cnt==n)
            return 0;
    }
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    int temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
string al="abcdefghijklmnopqrstuvwxyz";
pair<ll,ll>p[20000];
unordered_map <char,ll> mapp;
unordered_map <char,ll> mapp1;
vector<ll>vi;
vector<ll>vi1;
vector<ll>vi2;
ll n,sum,l,r,x,a[2000000],ma=-999999999999999999,i,cnt;
string s,t;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(i=1000000;i<=1000000+n-1;i++){
        cout<<i<<" ";
    }
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    if(n==1)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    int temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
string al="abcdefghijklmnopqrstuvwxyz";
pair<ll,ll>p[20000];
unordered_map <char,ll> mapp;
unordered_map <char,ll> mapp1;
vector<ll>vi;
vector<ll>vi1;
vector<ll>vi2;
ll n,sum,l,r,x,a[2000000],ma=-999999999999999999,i,cnt;
string s,t;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(i=1;i<=10000000000;i++){
        if(isPrime(i)){
            cout<<i<<" ";
            cnt++;
        }
        if(cnt==n)
            break;
    }
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    int temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
string al="abcdefghijklmnopqrstuvwxyz";
pair<ll,ll>p[20000];
unordered_map <char,ll> mapp;
unordered_map <char,ll> mapp1;
vector<ll>vi;
vector<ll>vi1;
vector<ll>vi2;
ll n,sum,l,r,x,a[2000000],ma=-999999999999999999,i,cnt;
string s,t;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(i=2;i<=10000000;i++){
        if(isPrime(i)){
            printf("%d ",i);
            cnt++;
            if(cnt==n){
            return 0;
           }
        }
    }
}


#include <iostream>

using namespace std;
int main(){
  int n, j=1;
  cin >> n;
  for(int i=2; i<n+2; i++, j++){
    cout << i+j << " ";
  }
  cout << endl;
}


#include <iostream>
using namespace std;

int main(){
  int a = 2;       //start from 2
  long long int b = 10000000;     //ends at 1000
  int counter = 0, n;
  cin >> n;
  for (int i = a; i <= b; i++){
    for (int j = 2; j <= i; j++){
      if (!(i%j)&&(i!=j)){
        break;
      }
      if (j==i){
        counter++;
        cout << i << " ";
      }
      if(counter==n) break;
    }
    if(counter==n) break;
  }
  cout << endl;
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;
int main(){
  int n;
  cin >> n;

  int sum = 0;
  int k = 2;
  for(int i=0; i<n; i++){
    cout << 11+sum << " ";
    sum+=k;
    if(sum % 11 == 0){
      k++;
      sum += k;
    }
    k++;
  }
  cout << endl;
}


#include <iostream>

using namespace std;
int main(){
  int n, j=0;
  cin >> n;
  for(int i=2; i<n+2; i++, j++){
    cout << i+j << " ";
  }
  cout << endl;
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;
int main(){
  int n;
  cin >> n;
  n*=3;
  for(int i=0; i<n; i++){
    cout << n << " ";
    n++;
  }
  cout << endl;
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;
int main(){
  int n;
  cin >> n;
  int tmp = n;
  n*=3;
  for(int i=0; i<tmp; i++){
    cout << n << " ";
    n++;
  }
  cout << endl;
}


#include <iostream>

using namespace std;

int main() {
	int n;
	int counter=0;
	cin >> n;
	cout << 1;
	for (int i=2;i<=10000000;i++) {
		if (i%(i-1) != 0) {
			cout << " " << i;
			counter++;
			if(counter==n-1) {
				cout << endl;
				return 0;
			}
		}
	}

}


#include <iostream>

using namespace std;

int main() {
	int n;
	int counter=0;
	cin >> n;
	cout << 2;
	for (int i=3;i<=10000000;i++) {
		if ((i-1)%i != 0) {
			cout << " " << i;
			counter++;
			if(counter==n-1) {
				cout << endl;
				return 0;
			}
		}
	}

}


#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int t;
#define maxn 100005
int main()
{
	int a[maxn] , n , cnt[maxn];
	cin >> t;
	int temp = 0 ;
	while(t--)
	{
		cin >> n;
		for(int i = 1 ; i <= n ; i ++)
		{
			cin >> a[i];
			memset(cnt , 0 ,sizeof(cnt));
			for(int j = 30 ; j >= 0 ; j--)
			{
				if((1<<j) & a[i])
				{
					cnt[j] ++ ;
					break ;
				}
			}
		}
		if(n == 1)
		{
			cout << 0 << endl ;
			continue ;
		}
		for(int j = 0 ; j <= 30 ; j++)
			temp += (cnt[j] * (cnt[j] - 1) ) / 2 ;
		cout << temp << endl;
		temp = 0;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int t;
#define maxn 100005
int main()
{
	int a[maxn] , n;
	cin >> t;
	int temp = 0 ;
	while(t--)
	{
		cin >> n;
		for(int i = 1 ; i <= n ; i ++)
			cin >> a[i];
		for(int i = 1 ; i <= n ; i ++)
			for(int j = i + 1 ; j <= n ; j ++)
				if((a[i] & a[j]) > (a[i] ^ a[j]))
					temp ++;
		cout << temp << endl;
		temp = 0;
	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n ;
        vector<int> v;
        while(n--){
            int a;
            cin >> a;
            v.push_back(a);
        }
        vector<int> m(32);
        for(int i : v){
            int k = 0;
            while(i){
                i = i>>1;
                k++;
            }
            m[k]++;
        }
        int ans = 0;
        for(int i : m){
            ans += i*(i-1) / 2;
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n ;
        vector<int> v;
        while(n--){
            int a;
            cin >> a;
            v.push_back(a);
        }
        vector<int> m(20);
        for(int i : v){
            int k = 0;
            while(i){
                i = i>>1;
                k++;
            }
            m[k]++;
        }
        int ans = 0;
        for(int i : m){
            if(i){
               ans += (1 << (i-1) ) -1;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n ;
        vector<int> v;
        while(n--){
            int a;
            cin >> a;
            v.push_back(a);
        }
        vector<int> m(32);
        for(int i : v){
            int k = 0;
            while(i){
                i = i>>1;
                k++;
            }
            m[k]++;
        }
        unsigned long long ans = 0;
        for(unsigned long long i : m){
            ans += i*(i-1) / 2;
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n ;
        vector<int> v;
        while(n--){
            int a;
            cin >> a;
            v.push_back(a);
        }
        vector<int> m(32);
        for(int i : v){
            int k = 0;
            while(i){
                i = i>>1;
                k++;
            }
            m[k]++;
        }
        long long ans = 0;
        for(int i : m){
            if(i>1){
               ans += ((long long)1 << (i-1) ) -1;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n ;
        vector<int> v;
        while(n--){
            int a;
            cin >> a;
            v.push_back(a);
        }
        vector<int> m(33);
        for(int i : v){
            int k = 0;
            while(i){
                i = i>>1;
                k++;
            }
            m[k]++;
        }
        int ans = 0;
        for(int i : m){
            if(i){
               ans += (1 << (i-1) ) -1;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		long count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		long answer = 0;
		for (int c: count) {
			answer += (c * (c - 1)) / 2;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		long long count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		long long answer = 0;
		for (long long c: count) {
			long long a, b;
			if (!(c%2)) {
				a = c / 2;
				b = c - 1;
			} else {
				a = c;
				b = (c - 1) / 2;
			}
			answer += a * b;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		int count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		int answer = 0;
		for (int c: count) {
			answer += (c * (c - 1)) / 2;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		long count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		long answer = 0;
		for (long c: count) {
			long a, b;
			if (!(c%2)) {
				a = c / 2;
				b = c - 1;
			} else {
				a = c;
				b = (c - 1) / 2;
			}
			answer += a * b;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		int count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		int answer = 0;
		for (int c: count) {
			int a, b;
			if (!(c%2)) {
				a = c / 2;
				b = c - 1;
			} else {
				a = c;
				b = (c - 1) / 2;
			}
			answer += a * b;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		long count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		long answer = 0;
		for (int c: count) {
			answer += ((long)c * (long)(c - 1)) / (long)2;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int log(int a, int b) {
	int result = 0;
	while (a) {
		a /= b;
		result += 1;
	}
	return result - 1;
}

int main() {
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n;
		long long count[31] = {0};
		while (n--) {
			cin >> i;
			count[log(i, 2)] += 1;
		}
		long long answer = 0;
		for (long long c: count) {
			answer += (c * (c - 1)) / 2;
		}
		cout << answer << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t,n,u,A[100],b;
bool p;

int main()
{
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        scanf("%d",&n);
        u = 0;
        for(int j=0; j<n; j++)
        {
            scanf("%d",&b);
            p = false;
            for(int s=2; p==false; s*=2)
            {
                if(b<s)
                {
                    u += A[s];
                    A[s]++;
                    p = true;
                }
            }
        }
        for(int j=0; j<100; j++)
        {
            A[j] = 0;
        }
        printf("%d\n",u);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t,n,u,A[100001],b;
bool p;

int main()
{
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        scanf("%d",&n);
        u = 0;
        for(int j=0; j<n; j++)
        {
            scanf("%d",&b);
            p = false;
            for(int s=2; p==false; s*=2)
            {
                if(b<s)
                {
                    A[j] = s;
                    p = true;
                }
            }
        }
        for(int j=0; j<n-1; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if(A[j]==A[k]) u++;
            }
        }
        printf("%d\n",u);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t,n,u,A[100],b,o;
bool p;

int main()
{
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        scanf("%d",&n);
        u = 0;
        for(int j=0; j<n; j++)
        {
            scanf("%d",&b);
            p = false;
            o = 0;
            for(int s=2; p==false; s*=2)
            {
                o++;
                if(b<s)
                {
                    u += A[o];
                    A[o]++;
                    p = true;
                }
            }
        }
        for(int j=0; j<100; j++)
        {
            A[j] = 0;
        }
        printf("%d\n",u);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t,n,u,A[50],b;
bool p;

int main()
{
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        scanf("%d",&n);
        u = 0;
        for(int j=0; j<n; j++)
        {
            scanf("%d",&b);
            p = false;
            for(int s=2; p==false; s*=2)
            {
                if(b<s)
                {
                    u += A[s];
                    A[s]++;
                    p = true;
                }
            }
        }
        for(int j=0; j<50; j++)
        {
            A[j] = 0;
        }
        printf("%d\n",u);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long t,n,u,A[100],b,o;
bool p;

int main()
{
    scanf("%lld",&t);
    for(long long i=0; i<t; i++)
    {
        scanf("%lld",&n);
        u = 0;
        for(long long j=0; j<n; j++)
        {
            scanf("%lld",&b);
            p = false;
            o = 0;
            for(long long s=2; p==false; s*=2)
            {
                o++;
                if(b<s)
                {
                    u += A[o];
                    A[o]++;
                    p = true;
                }
            }
        }
        for(long long j=0; j<100; j++)
        {
            A[j] = 0;
        }
        printf("%lld\n",u);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        cin>>n;
        vector<int> v(n), set_bit(n);
        for(int i=0; i<n; ++i){
            cin>>v[i];
            int cnt = 0;
            while(v[i]!=1){
                v[i]/=2;
                cnt++;
            }
            set_bit[i] = cnt+1;
        }
//        for(int i=0; i<n; ++i){
//            cout<<" "<<set_bit[i]<<endl;
//        }
        sort(set_bit.begin(), set_bit.end());
        set_bit.push_back(-1);
        long long ans =0;
        for(int i=0; i<n; ++i){
            long long same = 1;
            if(set_bit[i+1]==set_bit[i]){
                while(set_bit[i+1]==set_bit[i]){
                    i++;
                    same++;
                }
//                cout<<"same "<<same<<endl;
                i--;
                ans += (same*(same-1))/2;
            }
        }
        cout<<ans<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        cin>>n;
        vector<int> v(n), set_bit(n);
        for(int i=0; i<n; ++i){
            cin>>v[i];
            int cnt = 0;
            while(v[i]!=1){
                v[i]/=2;
                cnt++;
            }
            set_bit[i] = cnt+1;
        }
//        for(int i=0; i<n; ++i){
//            cout<<" "<<set_bit[i]<<endl;
//        }
        sort(set_bit.begin(), set_bit.end());
        set_bit.push_back(-1);
        long long ans =0;
        for(int i=0; i<n; ++i){
            int same = 1;
            if(set_bit[i+1]==set_bit[i]){
                while(set_bit[i+1]==set_bit[i]){
                    i++;
                    same++;
                }
//                cout<<"same "<<same<<endl;
                i--;
                ans += (same*(same-1))/2;
            }
        }
        cout<<ans<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        cin>>n;
        vector<int> v(n), set_bit(n);
        for(int i=0; i<n; ++i){
            cin>>v[i];
            int cnt = 0;
            while(v[i]!=1){
                v[i]/=2;
                cnt++;
            }
            set_bit[i] = cnt+1;
        }
        sort(set_bit.begin(), set_bit.end());
        set_bit.push_back(-1);
        int ans =0;
        for(int i=0; i<n; ++i){
            int same = 1;
            if(set_bit[i+1]==set_bit[i]){
                while(set_bit[i+1]==set_bit[i]){
                    i++;
                    same++;
                }
                i--;
                ans += (same*(same-1))/2;
            }
        }
        cout<<ans<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        cin>>n;
        vector<int> v(n), set_bit(n);
        for(int i=0; i<n; ++i){
            cin>>v[i];
            int cnt = 0;
            while(v[i]!=1){
                v[i]/=2;
                cnt++;
            }
            set_bit[i] = cnt+1;
        }
        for(int i=0; i<n; ++i){
            cout<<" "<<set_bit[i]<<endl;
        }
        sort(set_bit.begin(), set_bit.end());
        set_bit.push_back(-1);
        long long ans =0;
        for(int i=0; i<n; ++i){
            int same = 1;
            if(set_bit[i+1]==set_bit[i]){
                while(set_bit[i+1]==set_bit[i]){
                    i++;
                    same++;
                }
                cout<<"same "<<same<<endl;
                i--;
                ans += (same*(same-1))/2;
            }
        }
        cout<<ans<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],now,sum;
long long ans,num;
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		ans=0,now=1,sum=0;
		for(int i=1; i<=n; i++)scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i=1; i<=n; i++) {
			if(a[i]>now*2)now*=2;
			if(now!=a[i]) {
				int p1=upper_bound(a+1,a+n+1,now)-a;
				int p2=lower_bound(a+1,a+n+1,a[i])-a;
				ans+=(p2-p1);
				sum=0;
			} else {
				ans+=sum;
				sum++;
			}
		}
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],now,sum,p1,p2;
long long ans,num;
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		ans=0,now=1,sum=0;
		for(int i=1; i<=n; i++)scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i=1; i<=n; i++) {
			while(a[i]>=now*2)now*=2,sum=0;
			if(now!=a[i]) {
				p1=lower_bound(a+1,a+n+1,now)-a;
				p2=upper_bound(a+1,a+n+1,a[i])-a-1;
				ans+=(p2-p1);
				sum=0;
			} else {
				ans+=sum;
				sum++;
			}
		}
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],now,sum,p1,p2;
long long ans,num;
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		ans=0,now=1,sum=0;
		for(int i=1; i<=n; i++)scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i=1; i<=n; i++) {
			while(a[i]>=now*2)now*=2,sum=0;
			if(now!=a[i]) {
				p1=lower_bound(a+1,a+n+1,now)-a;
				p2=lower_bound(a+1,a+n+1,a[i])-a;
				ans+=(p2-p1);
				sum=0;
			} else {
				ans+=sum;
				sum++;
			}
		}
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],now,sum,p1,p2;
long long ans;
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		ans=0,now=1,sum=0;
		for(int i=1; i<=n; i++)scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i=1; i<=n; i++) {
			while(a[i]>=now*2)now*=2,sum=0;
			ans+=sum;
			sum++;
			/*if(now!=a[i]) {
				p1=lower_bound(a+1,a+n+1,now)-a;
				p2=upper_bound(a+1,a+n+1,a[i])-a-1;
				ans+=(p2-p1);
				sum=0;
			} else {
				ans+=sum;
				sum++;
			}*/
		}
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],now,sum,p1,p2;
long long ans,num;
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		ans=0,now=1,sum=0;
		for(int i=1; i<=n; i++)scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i=1; i<=n; i++) {
			if(a[i]>=now*2)now*=2,sum=0;
			if(now!=a[i]) {
				p1=lower_bound(a+1,a+n+1,now)-a;
				p2=lower_bound(a+1,a+n+1,a[i])-a;
				ans+=(p2-p1);
				sum=0;
			} else {
				ans+=sum;
				sum++;
			}
		}
		printf("%lld\n",ans);
	}
}


#include <bits/stdc++.h>
using namespace std;

#define forr(i,a,b) for(ll i=(a);i<(b);++i)
#define forn(i,n) forr(i,0,n)
#define dforr(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define dforn(i,n) dforr(i,0,n)
#define fore(e,v) for(auto e:v)
#define dprint(v) cout<<#v" = "<<v<<'\n'
#define vecp(v) fore(ee,v)cout<<ee<<' '; cout<<"\n"
#define veij(v, i, j) forn(iiii, j-i) cout<<v[iiii+i]<<' '; cout<<'\n'       // [i, j)
#define vei(v, i) veij(v, i, sz(v))                                          // [i, sz(v))
#define grap(g) fore(ff,g){vecp(ff);} cout<<'\n'
#define arrp(f,n) forn(ii,n)cout<<f[ii]<<' '; cout<<'\n'
#define matp(g,n,m) forn(jj,n){arrp(g[jj],m);} cout<<'\n'
#define llenar(a,b) memset(a,b,sizeof a)
#define zero(a) llenar(a,0)
#define all(v) v.begin(),v.end()
#define ordenar(v) sort(all(v))
#define sz(v) ((ll)v.size())
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef unsigned long long ull;
typedef long double real;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll MAXN = 1e5+100;
const ll INF = 1e18+100;
const ll MOD = 1e9+7;

//___________________________

int main(){

/*
freopen("nim.out", "w", stdout);
freopen("nim.in", "r", stdin);
*/

ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

ll t, ff=0;

cin>>t;

if(t==10)
{
    ff=1;
}

while(t--)
{
    ll n, a[100010], b, s=0;

    cin>>n;

    vll l(35, 0);

    forn(i, n)
    {
        cin>>a[i];

        b=log2(a[i]);

        l[b]++;

    }

    forn(i, 35)
    {
        if(l[i]>1)
        {
            s+=(l[i]*(l[i]-1))/2;
        }
    }

    cout<<s<<endl;

}

return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forr(i,a,b) for(ll i=(a);i<(b);++i)
#define forn(i,n) forr(i,0,n)
#define dforr(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define dforn(i,n) dforr(i,0,n)
#define fore(e,v) for(auto e:v)
#define dprint(v) cout<<#v" = "<<v<<'\n'
#define vecp(v) fore(ee,v)cout<<ee<<' '; cout<<"\n"
#define veij(v, i, j) forn(iiii, j-i) cout<<v[iiii+i]<<' '; cout<<'\n'       // [i, j)
#define vei(v, i) veij(v, i, sz(v))                                          // [i, sz(v))
#define grap(g) fore(ff,g){vecp(ff);} cout<<'\n'
#define arrp(f,n) forn(ii,n)cout<<f[ii]<<' '; cout<<'\n'
#define matp(g,n,m) forn(jj,n){arrp(g[jj],m);} cout<<'\n'
#define llenar(a,b) memset(a,b,sizeof a)
#define zero(a) llenar(a,0)
#define all(v) v.begin(),v.end()
#define ordenar(v) sort(all(v))
#define sz(v) ((ll)v.size())
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef unsigned long long ull;
typedef long double real;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll MAXN = 1e5+100;
const ll INF = 1e18+100;
const ll MOD = 1e9+7;

//___________________________

int main(){

/*
freopen("nim.out", "w", stdout);
freopen("nim.in", "r", stdin);
*/

ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

ll t;

cin>>t;

while(t--)
{
    ll n, a[100010], b, s=0;

    cin>>n;

    vll l(n, 0);

    forn(i, n)
    {
        cin>>a[i];

        b=log2(a[i]);

        l[b]++;

    }

    forn(i, n)
    {
        if(l[i]>1)
        {
            s+=(l[i]*(l[i]-1))/2;
        }
    }

    cout<<s<<endl;

}

return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forr(i,a,b) for(ll i=(a);i<(b);++i)
#define forn(i,n) forr(i,0,n)
#define dforr(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define dforn(i,n) dforr(i,0,n)
#define fore(e,v) for(auto e:v)
#define dprint(v) cout<<#v" = "<<v<<'\n'
#define vecp(v) fore(ee,v)cout<<ee<<' '; cout<<"\n"
#define veij(v, i, j) forn(iiii, j-i) cout<<v[iiii+i]<<' '; cout<<'\n'       // [i, j)
#define vei(v, i) veij(v, i, sz(v))                                          // [i, sz(v))
#define grap(g) fore(ff,g){vecp(ff);} cout<<'\n'
#define arrp(f,n) forn(ii,n)cout<<f[ii]<<' '; cout<<'\n'
#define matp(g,n,m) forn(jj,n){arrp(g[jj],m);} cout<<'\n'
#define llenar(a,b) memset(a,b,sizeof a)
#define zero(a) llenar(a,0)
#define all(v) v.begin(),v.end()
#define ordenar(v) sort(all(v))
#define sz(v) ((ll)v.size())
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef unsigned long long ull;
typedef long double real;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll MAXN = 1e5+100;
const ll INF = 1e18+100;
const ll MOD = 1e9+7;

//___________________________

int main(){

/*
freopen("nim.out", "w", stdout);
freopen("nim.in", "r", stdin);
*/

ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

ll t;

cin>>t;

while(t--)
{
    ll n, a[100010], b, s=0;

    cin>>n;

    vll l(35, 0);

    forn(i, n)
    {
        cin>>a[i];

        b=log2(a[i]);

        l[b]++;

    }

    forn(i, 35)
    {
        if(l[i]>1)
        {
            s+=(l[i]*(l[i]-1))/2;
        }
    }

    cout<<s<<endl;

}

return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forr(i,a,b) for(ll i=(a);i<(b);++i)
#define forn(i,n) forr(i,0,n)
#define dforr(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define dforn(i,n) dforr(i,0,n)
#define fore(e,v) for(auto e:v)
#define dprint(v) cout<<#v" = "<<v<<'\n'
#define vecp(v) fore(ee,v)cout<<ee<<' '; cout<<"\n"
#define veij(v, i, j) forn(iiii, j-i) cout<<v[iiii+i]<<' '; cout<<'\n'       // [i, j)
#define vei(v, i) veij(v, i, sz(v))                                          // [i, sz(v))
#define grap(g) fore(ff,g){vecp(ff);} cout<<'\n'
#define arrp(f,n) forn(ii,n)cout<<f[ii]<<' '; cout<<'\n'
#define matp(g,n,m) forn(jj,n){arrp(g[jj],m);} cout<<'\n'
#define llenar(a,b) memset(a,b,sizeof a)
#define zero(a) llenar(a,0)
#define all(v) v.begin(),v.end()
#define ordenar(v) sort(all(v))
#define sz(v) ((ll)v.size())
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef unsigned long long ull;
typedef long double real;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll MAXN = 1e5+100;
const ll INF = 1e18+100;
const ll MOD = 1e9+7;

ll p[35];

ll f(ll x)
{
    ll a=-1, b=35;

    while(b-a>1)
    {
        ll m=(a+b)/2;

        if(p[m]>x)
            b=m;
        else
            a=m;

    }

    return a;

}

//___________________________

int main(){

/*
freopen("nim.out", "w", stdout);
freopen("nim.in", "r", stdin);
*/

ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

p[0]=1;
forr(i, 1, 35)
{
    p[i]=2*p[i-1];
}

ll t;

cin>>t;

while(t--)
{
    ll n, a[100010], b, s=0;

    cin>>n;

    vll l(n, 0);

    forn(i, n)
    {
        cin>>a[i];

        b=f(a[i]);

        l[b]++;

    }

    forn(i, n)
    {
        if(l[i]>1)
        {
            if(l[i]%2)
                s+=l[i]*((l[i]-1)/2);
            else
                s+=l[i]/2*(l[i]-1);
        }
    }

    cout<<s<<endl;

}

return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forr(i,a,b) for(ll i=(a);i<(b);++i)
#define forn(i,n) forr(i,0,n)
#define dforr(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define dforn(i,n) dforr(i,0,n)
#define fore(e,v) for(auto e:v)
#define dprint(v) cout<<#v" = "<<v<<'\n'
#define vecp(v) fore(ee,v)cout<<ee<<' '; cout<<"\n"
#define veij(v, i, j) forn(iiii, j-i) cout<<v[iiii+i]<<' '; cout<<'\n'       // [i, j)
#define vei(v, i) veij(v, i, sz(v))                                          // [i, sz(v))
#define grap(g) fore(ff,g){vecp(ff);} cout<<'\n'
#define arrp(f,n) forn(ii,n)cout<<f[ii]<<' '; cout<<'\n'
#define matp(g,n,m) forn(jj,n){arrp(g[jj],m);} cout<<'\n'
#define llenar(a,b) memset(a,b,sizeof a)
#define zero(a) llenar(a,0)
#define all(v) v.begin(),v.end()
#define ordenar(v) sort(all(v))
#define sz(v) ((ll)v.size())
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef unsigned long long ull;
typedef long double real;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll MAXN = 1e5+100;
const ll INF = 1e18+100;
const ll MOD = 1e9+7;

//___________________________

int main(){

/*
freopen("nim.out", "w", stdout);
freopen("nim.in", "r", stdin);
*/

ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

ll t, ff=0;

cin>>t;

if(t==10)
{
    ff=1;
}

while(t--)
{
    ll n, a[100010], b, s=0;

    cin>>n;

    vll l(n, 0);

    forn(i, n)
    {
        cin>>a[i];

        b=log2(a[i]);

        l[b]++;

    }

    forn(i, n)
    {
        if(l[i]>1)
        {
            s+=(l[i]*(l[i]-1))/2;
        }
    }

    cout<<s<<endl;

    if(ff && t<5)
    {
        forn(i, n)
        {
            cout<<a[i]<<' ';
        }
        cout<<endl;
    }

}

return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forr(i,a,b) for(ll i=(a);i<(b);++i)
#define forn(i,n) forr(i,0,n)
#define dforr(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define dforn(i,n) dforr(i,0,n)
#define fore(e,v) for(auto e:v)
#define dprint(v) cout<<#v" = "<<v<<'\n'
#define vecp(v) fore(ee,v)cout<<ee<<' '; cout<<"\n"
#define veij(v, i, j) forn(iiii, j-i) cout<<v[iiii+i]<<' '; cout<<'\n'       // [i, j)
#define vei(v, i) veij(v, i, sz(v))                                          // [i, sz(v))
#define grap(g) fore(ff,g){vecp(ff);} cout<<'\n'
#define arrp(f,n) forn(ii,n)cout<<f[ii]<<' '; cout<<'\n'
#define matp(g,n,m) forn(jj,n){arrp(g[jj],m);} cout<<'\n'
#define llenar(a,b) memset(a,b,sizeof a)
#define zero(a) llenar(a,0)
#define all(v) v.begin(),v.end()
#define ordenar(v) sort(all(v))
#define sz(v) ((ll)v.size())
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef unsigned long long ull;
typedef long double real;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll MAXN = 1e5+100;
const ll INF = 1e18+100;
const ll MOD = 1e9+7;

ll p[35];

ll f(ll x)
{
    ll a=-1, b=35;

    while(b-a>1)
    {
        ll m=(a+b)/2;

        if(p[m]>x)
            b=m;
        else
            a=m;

    }

    return a;

}

//___________________________

int main(){

/*
freopen("nim.out", "w", stdout);
freopen("nim.in", "r", stdin);
*/

ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

p[0]=1;
forr(i, 1, 35)
{
    p[i]=2*p[i-1];
}

ll t;

cin>>t;

while(t--)
{
    ll n, a[100010], b, s=0;

    cin>>n;

    vll l(n, 0);

    forn(i, n)
    {
        cin>>a[i];

        b=f(a[i]);

        l[b]++;

    }

    forn(i, n)
    {
        if(l[i]>1)
        {
            s+=(l[i]*(l[i]-1))/2;
        }
    }

    cout<<s<<endl;

}

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T> bool umin(T& a, const T& b) {
    return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
    return a<b?a=b, 1:0;
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x){
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}

template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
    write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
    x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
    EACH(a, x)
        offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
    EACH(a, x)
        offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
    return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T, class U> void vti(vt<T> &v, U x, size_t n) {
    v=vt<T>(n, x);
}
template<class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v=vt<T>(n);
    EACH(a, v)
        vti(a, x, m);
}
int countBits(int n){
    int cnt=0;
    while(n){
        n/=2;
        cnt++;
    }
    return cnt;
}
map<int,int>cnt;
void solve() {
  int n;
  read(n);
  vector<int>a(n);
  read(a);
  int ans=0;
  vector<ll>v(32,0);
  cnt.clear();
  vector<bool>vis(32,false);
  for(int i=0;i<n;i++){
    int numBits=countBits(a[i]);
    //cout<<numBits;
    v[numBits]++;

    /*int st=0,ed=i;
    while(st<=ed){
        int md=(st+ed)/2;
        if(countBits(a[md])==numBits)
            st=md+1,ans++;
        else ed=md-1;
    }*/
  }
  for(int i=0;i<n;i++)
  {
    int num=countBits(a[i]);
    if(v[num]<=1)continue;
    if(!vis[num])
    ans+=((v[num]*(v[num]-1))/2),vis[num]=true;
  }
  print(ans);

}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    read(t);
    FOR(t) {
        //write("Case #", i+1, ": ");
        solve();
        //write("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T> bool umin(T& a, const T& b) {
    return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
    return a<b?a=b, 1:0;
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x){
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}

template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
    write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
    x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
    EACH(a, x)
        offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
    EACH(a, x)
        offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
    return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T, class U> void vti(vt<T> &v, U x, size_t n) {
    v=vt<T>(n, x);
}
template<class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v=vt<T>(n);
    EACH(a, v)
        vti(a, x, m);
}
int countBits(int n){
    int cnt=0;
    while(n){
        n/=2;
        cnt++;
    }
    return cnt;
}
 map<int,int>cnt;
void solve() {
  int n;
  read(n);
  vector<int>a(n);
  read(a);
  int ans=0;
  sort(a.begin(),a.end());
  vector<int>v(32,0);
  cnt.clear();
  vector<bool>vis(32,false);
  for(int i=0;i<n;i++){
    int numBits=countBits(a[i]);
    cnt[a[i]]++;
    //cout<<numBits;
    v[numBits]++;

    /*int st=0,ed=i;
    while(st<=ed){
        int md=(st+ed)/2;
        if(countBits(a[md])==numBits)
            st=md+1,ans++;
        else ed=md-1;
    }*/
  }
  for(int i=0;i<n;i++)
  {
    int num=countBits(a[i]);
    if(v[num]<=1)continue;
    if(!vis[num])
    ans+=max(v[num]-(cnt[a[i]]!=v[num]),0),vis[num]=true;
  }
  print(ans);

}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    read(t);
    FOR(t) {
        //write("Case #", i+1, ": ");
        solve();
        //write("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T> bool umin(T& a, const T& b) {
    return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
    return a<b?a=b, 1:0;
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x){
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}

template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
    write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
    x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
    EACH(a, x)
        offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
    EACH(a, x)
        offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
    return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T, class U> void vti(vt<T> &v, U x, size_t n) {
    v=vt<T>(n, x);
}
template<class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v=vt<T>(n);
    EACH(a, v)
        vti(a, x, m);
}
int countBits(int n){
    int cnt=0;
    while(n){
        n/=2;
        cnt++;
    }
    return cnt;
}
map<int,int>cnt;
void solve() {
  int n;
  read(n);
  vector<int>a(n);
  read(a);
  ll ans=0;
  vector<ll>v(32,0);
  cnt.clear();
  vector<bool>vis(32,false);
  for(int i=0;i<n;i++){
    int numBits=countBits(a[i]);
    //cout<<numBits;
    v[numBits]++;

    /*int st=0,ed=i;
    while(st<=ed){
        int md=(st+ed)/2;
        if(countBits(a[md])==numBits)
            st=md+1,ans++;
        else ed=md-1;
    }*/
  }
  for(int i=0;i<n;i++)
  {
    int num=countBits(a[i]);
    if(v[num]<=1)continue;
    if(!vis[num])
    ans+=((v[num]*(v[num]-1))/2),vis[num]=true;
  }
  print(ans);

}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    read(t);
    FOR(t) {
        //write("Case #", i+1, ": ");
        solve();
        //write("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T> bool umin(T& a, const T& b) {
    return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
    return a<b?a=b, 1:0;
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x){
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}

template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
    write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
    x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
    EACH(a, x)
        offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
    EACH(a, x)
        offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
    return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T, class U> void vti(vt<T> &v, U x, size_t n) {
    v=vt<T>(n, x);
}
template<class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v=vt<T>(n);
    EACH(a, v)
        vti(a, x, m);
}
int countBits(int n){
    int cnt=0;
    while(n){
        n/=2;
        cnt++;
    }
    return cnt;
}
void solve() {
  int n;
  read(n);
  vector<int>a(n);
  read(a);
  ll ans=0;
  vector<ll>v(32,0);
  vector<bool>vis(32,false);
  for(int i=0;i<n;i++){
    int numBits=countBits(a[i]);
    v[numBits]++;
  }
  for(int i=0;i<n;i++)
  {
    int num=countBits(a[i]);
    if(v[num]<=1)continue;
    if(!vis[num])
    ans+=((v[num]*(v[num]-1))/2),vis[num]=true;
  }
  print(ans);

}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    read(t);
    FOR(t) {
        //write("Case #", i+1, ": ");
        solve();
        //write("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T> bool umin(T& a, const T& b) {
    return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
    return a<b?a=b, 1:0;
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x){
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}

template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
    write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
    x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
    EACH(a, x)
        offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
    EACH(a, x)
        offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
    return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T, class U> void vti(vt<T> &v, U x, size_t n) {
    v=vt<T>(n, x);
}
template<class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v=vt<T>(n);
    EACH(a, v)
        vti(a, x, m);
}
int countBits(int n){
    int cnt=0;
    while(n){
        n/=2;
        cnt++;
    }
    return cnt;
}
map<int,int>cnt;
void solve() {
  int n;
  read(n);
  vector<int>a(n);
  ll ans=0;
  vector<ll>v(32,0);
  cnt.clear();
  vector<bool>vis(32,false);
  for(int i=0;i<n;i++){
    int numBits=countBits(a[i]);
    //cout<<numBits;
    v[numBits]++;

    /*int st=0,ed=i;
    while(st<=ed){
        int md=(st+ed)/2;
        if(countBits(a[md])==numBits)
            st=md+1,ans++;
        else ed=md-1;
    }*/
  }
  for(int i=0;i<n;i++)
  {
    int num=countBits(a[i]);
    if(v[num]<=1)continue;
    if(!vis[num])
    ans+=((v[num]*(v[num]-1))/2),vis[num]=true;
  }
  print(ans);

}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    read(t);
    FOR(t) {
        //write("Case #", i+1, ": ");
        solve();
        //write("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve ()
{
    int n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    vector<bool>vis(n,false);
    ll total=0;
    for(int i=31; i>=0; i--)
    {
        ll num=0;
        for(int j=0; j<n; j++)
        {
            if((1<<i)&(a[j]) && !vis[j])
                num++;
        }
        for(int j=0; j<n; j++)
        {
            if((1<<i)&(a[j]) && !vis[j])
                vis[j]=true;
        }
        total+=(num*(num-1))/2;
    }
    cout<<total<<"\n";
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void solve ()
{
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    vector<bool>vis(n,false);
    for(int j=31; j>=0; j--)
    {
        ll cnt=0;
        for(int i=0; i<n; i++)
        {
            if((1<<j)&(a[i]) && !vis[i])
            {
                cnt++;
                vis[i]=true;
            }
        }
        ans+=((cnt*(cnt-1))/2);
    }
    cout<<ans<<endl;
}
int main()
{
    Boost();

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve ()
{
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    vector<bool>vis(n,false);
    for(int j=31; j>=0; j--)
    {
        ll cnt=0;
        for(int i=0; i<n; i++)
        {
            if((1<<j)&(a[i]) && !vis[i])
                cnt++;
        }
        for(int i=0; i<n; i++)
        {
            if((1<<j)&(a[i]) && !vis[i])
                vis[i]=true;
        }
        ans+=((cnt*(cnt-1))/2);
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[1000000];
long long b[100];
long long c[100];
long long T,js=0,n,ans=0,hj;
int main()
{
 ios::sync_with_stdio(false);
    b[1]=1;
   for(int i=2;i<40;i++)
   {
   	b[i]=2*(b[i-1]+1)-1;
   }
 cin>>T;
 while(T--)
 {
 	ans=0;
 	cin>>n;
 	for (int i=1;i<n+1;i++)
 	 {
 	 	cin>>hj;
 	 	for(int j=1;j<40;j++)
 	 	{
 	 		if(b[j]>=hj) {
 	 		                c[j]++;

 	 		                break;
			              }
		  }
	  }

   for(int i=1;i<40;i++)
   {
   	 if(c[i]>1){
				  ans+=c[i]*(c[i]-1)/2;
				  js=0;
		       }
   }
	cout<<ans<<endl;

	js=1;
	for(int i=1;i<40;i++)
	{
		c[i]=0;
	}
  }
 return 0;
}


    #include<bits/stdc++.h>
    #define rep(i,a,n) for(register int i=a;i<=n;++i)
    #define per(i,a,n) for(register int i=a;i>=n;--i)
    #define mem(a) memset(a,0,sizeof(a))
    #define elif else if
    #define mid (l+r)/2
    using namespace std;
    typedef unsigned long long ull;
    typedef long long ll;
    inline ll read()
    {
        ll f=1,x=0;
        char ch;
        do
        {
            ch=getchar();
            if(ch=='-')
            f=-1;
        }
        while(ch<'0'||ch>'9');
        do
        {
            x=x*10+ch-'0';
            ch=getchar();
        }
        while(ch>='0'&&ch<='9');
        return f*x;
    }
    long long halogen(int k)
    {
    	int t=1,p=0;
    	while(1)
    	{
    		if(k<t)
    		return p;
    		t*=2;
    		++p;
    	}
    }
    int main()
    {
    	long long t,n,m,a[100001],b[51],c;
    	t=read();
    	rep(kkk,1,t)
    	{
    		n=read();
    		mem(b);
    		c=0;
    		rep(i,1,n)
    		{
    			a[i]=read();
    			m=halogen(a[i]);
    //			cout<<a[i]<<' '<<m<<endl;
    			c+=b[m];
    			++b[m];
    		}
    		printf("%d\n",c);
    	}
        return 0;
    }


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return N ? 32 - __builtin_clz(N) : INT_MIN;
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(34);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[leftmostBit(a[i])]++;
	for (int i = 1; i <= 33; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(ull i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return N ? 32 - __builtin_clz(N) : INT_MIN;
}

int ch2(ull n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<ull> a(n), bit(18);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[leftmostBit(a[i])]++;
	for (int i = 1; i <= 17; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return 32 - __builtin_clz(N);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

int msb(unsigned x) {
	union { double a; int b[2]; };
	a = x;
	return (b[1] >> 20) - 1023;
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(33, 0);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[clz(a[i])]++;
	for (int i = 1; i <= 32; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (i >> 1);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(17);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[leftmostBit(a[i])]++;
	for (int i = 1; i <= 16; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
//	int t;
//	cin >> t;
//	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return 32 - __builtin_clz(N);
}

long long ch2(int n) {
	return ((1LL * n * (n - 1) / 2));
}

int msb(unsigned x) {
	union { double a; int b[2]; };
	a = x;
	return (b[1] >> 20) - 1023;
}

void solve() {
	int n;
	long long cnt = 0;
	cin >> n;
	vector<int> a(n), bit(33, 0);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[clz(a[i])]++;
	for (int i = 1; i <= 32; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return N ? 32 - __builtin_clz(N) : INT_MIN;
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(18);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[leftmostBit(a[i])]++;
	for (int i = 1; i <= 17; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (i >> 1);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(17);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[leftmostBit(a[i])]++;
	for (int i = 1; i <= 16; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(unsigned N) {
    return 32 - __builtin_clz(N);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

int msb(unsigned x) {
	union { double a; int b[2]; };
	a = x;
	return (b[1] >> 20) - 1023;
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<unsigned> a(n), bit(33, 0);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[clz(a[i])]++;
	for (int i = 1; i <= 32; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return 32 - __builtin_clz(N);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

int msb(unsigned x) {
	union { double a; int b[2]; };
	a = x;
	return (b[1] >> 20) - 1023;
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<unsigned> a(n), bit(33, 0);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[msb(a[i])]++;
	for (int i = 1; i <= 32; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (i >> 1);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(17);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[leftmostBit(a[i])]++;
	for (int i = 1; i <= 16; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cout << _.first << ' ' << _.second << endl;} cout << endl;
#define ull unsigned long long
using namespace std;

int leftmostBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (((unsigned)i) >> 1);
}

int clz(int N) {
    return 32 - __builtin_clz(N);
}

int ch2(int n) {
	return ((n * (n - 1) / 2));
}

void solve() {
	int n, cnt = 0;
	cin >> n;
	vector<int> a(n), bit(33);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) bit[clz(a[i])]++;
	for (int i = 1; i <= 33; ++i) {
		//cout << i << " : " << bit[i] << endl;
		cnt += ch2(bit[i]);
	}
	cout << cnt << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define ri register int
#define ll long long
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid+1, r
using namespace std;
void re(int &x){
	x = 0;
	int b = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-') b = 1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	if(b == 1)
		x *= -1;
}
const int maxn = 1010;
int n, m,  t;
int a[maxn], b[maxn];
char s[maxn];
int z[maxn];
int work(int x){
	int cnt = 0;
	while(x){
		cnt ++;
		x >>= 1;
	}
	return cnt;
}
int main(){
	re(t);
	while(t --){
		re(n);
		long long ans = 0;
		memset(a,0,sizeof(a));
		for(int i = 1;i <= n;i ++){
			int x;
			re(x);
			x = work(x);
			a[x] ++;
			//cout << x << " " ;
		}
		for(int i = 1;i <= 100;i ++)
			ans = ans + max(a[i]*(a[i]-1)/2, 0);
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define ri register int
#define ll long long
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid+1, r
using namespace std;
void re(int &x){
	x = 0;
	int b = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-') b = 1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	if(b == 1)
		x *= -1;
}
const int maxn = 1010;
int n, m,  t;
ll a[maxn], b[maxn];
char s[maxn];
int z[maxn];
int work(int x){
	int cnt = 0;
	while(x){
		cnt ++;
		x >>= 1;
	}
	return cnt;
}
int main(){
	re(t);
	while(t --){
		re(n);
		long long ans = 0;
		memset(a,0,sizeof(a));
		for(int i = 1;i <= n;i ++){
			int x;
			re(x);
			x = work(x);
			a[x] ++;
			//cout << x << " " ;
		}
		for(int i = 1;i <= 100;i ++)
			ans = ans + max(1ll*a[i]*(a[i]-1)/2, 1ll*0);
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define ri register int
#define ll long long
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid+1, r
using namespace std;
void re(int &x){
	x = 0;
	int b = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-') b = 1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	if(b == 1)
		x *= -1;
}
const int maxn = 1010;
int n, m, ans, t;
int a[maxn], b[maxn];
char s[maxn];
int z[maxn];
int work(int x){
	int cnt = 0;
	while(x){
		cnt ++;
		x >>= 1;
	}
	return cnt;
}
int main(){
	re(t);
	while(t --){
		re(n);
		ans = 0;
		memset(a,0,sizeof(a));
		for(int i = 1;i <= n;i ++){
			int x;
			re(x);
			x = work(x);
			a[x] ++;
			//cout << x << " " ;
		}
		for(int i = 1;i <= 64;i ++)
			ans = ans + max(a[i]*(a[i]-1)/2, 0);
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define ri register int
#define ll long long
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid+1, r
using namespace std;
void re(int &x){
	x = 0;
	int b = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-') b = 1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	if(b == 1)
		x *= -1;
}
const int maxn = 101000;
int n, m,  t;
ll a[maxn], b[maxn];
char s[maxn];
int z[maxn];
int work(int x){
	int cnt = 0;
	while(x){
		cnt ++;
		x >>= 1;
	}
	return cnt;
}
int main(){
	re(t);
	while(t --){
		re(n);
		long long ans = 0;
		memset(a,0,sizeof(a));
		for(int i = 1;i <= n;i ++){
			int x;
			re(x);
			x = work(x);
			a[x] ++;
			//cout << x << " " ;
		}
		for(int i = 1;i <= 100;i ++)
			ans = ans + max(1ll*a[i]*(a[i]-1)/2, 1ll*0);
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int i,j,k,l,m,n,t;
	cin>>t;
	while(t--)
	{
		k=0;
		cin>>n;
		int A[n];
		for(i=1;i<=n;i++)
		{
			cin>>A[i];
		}
		for(i=1;i<n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				if(((A[i]&A[j])>=(A[i]^A[j])))
				{
					k++;
				}
			}
		}
		cout<<k<<endl;;
	}
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int i,j,k,l,m,n,t;
	cin>>t;
	while(t--)
	{
		long long int sum=0,p;
		cin>>n;
	long long 	int A[n],B[50];
		for(i=1;i<=40;i++)
        {
         B[i]=0;
		}
		for(i=1;i<=n;i++)
		{
			cin>>A[i];
			p=log2(A[i])+1;
			B[p]=B[p]+1;
		}
		for(i=1;i<=40;i++)
		{
			sum=sum+(B[i]*(B[i]-1))/2;
		}
		cout<<sum<<endl;

	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,k,l,m,n,t;
	cin>>t;
	while(t--)
	{
		j=0;
		cin>>n;
		int A[n],B[n];
		for(i=1;i<=n;i++)
		{
			cin>>A[i];
			B[i]=A[i];
		}
		sort(A+1,A+n+1,greater<int>());
		for(i=1;i<n;i++)
		{
			if(A[i]==A[i+1])
			{
				j=-100;
			}
		}
		for(i=1;i<=n;i++)
		{
			 if(B[i]==A[i])
			 {
			 	j++;

			 }

		}
		if(j==n)
		{
			cout<<"NO"<<endl;
		}
		 else
		 {
		 	cout<<"YES"<<endl;
		 }
	}
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int i,j,k,l,m,n,t;
	cin>>t;
	while(t--)
	{
		int sum=0,p;
		cin>>n;
		int A[n],B[50];
		for(i=1;i<=40;i++)
        {
         B[i]=0;
		}
		for(i=1;i<=n;i++)
		{
			cin>>A[i];
			p=log2(A[i])+1;
			B[p]=B[p]+1;
		}
		for(i=1;i<=40;i++)
		{
			sum=sum+(B[i]*(B[i]-1))/2;
		}
		cout<<sum<<endl;

	}
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int i,j,k,l,m,n,t;
	cin>>t;
	while(t--)
	{
		long long int sum=0,p;
		cin>>n;
		int A[n],B[50];
		for(i=1;i<=40;i++)
        {
         B[i]=0;
		}
		for(i=1;i<=n;i++)
		{
			cin>>A[i];
			p=log2(A[i])+1;
			B[p]=B[p]+1;
		}
		for(i=1;i<=40;i++)
		{
			sum=sum+(B[i]*(B[i]-1))/2;
		}
		cout<<sum<<endl;

	}
}


#include<bits/stdc++.h>
using namespace std;
int num[100011];
int main(){
    int T,N;
    long long int ans;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&N);
        if(N==1)
            printf("0\n");
        else{
            ans=(N*(N-1))/2;
            for(int i=0;i<N;i++)
                scanf("%d",&num[i]);
            for(int i=0;i<N;i++)
                for(int j=i+1;j<N;j++)
                    if(i==j)
                        continue;
                    else if((num[i]&num[j])<(num[i]^num[j]))
                        ans--;
            printf("%lld\n",ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int num[100011];
int main(){
    int T,N;
    long long int ans;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&N);
        if(N==1)
            printf("0\n");
        else{
            int ans=0;
            map<int,int>ma;
            for(int i=0;i<N;i++){
                scanf("%d",&num[i]);
                int temp=0;
                while(num[i]!=0){
                    num[i]=num[i]>>1;
                    temp++;
                }
                ma[temp]++;
            }
            for(map<int,int>::iterator it=ma.begin();it!=ma.end();it++)
                if(it->second>1)
                    ans+=(it->second)*(it->second-1)/2;
            printf("%lld\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int temp, T, N;
long long int ans;
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        ans=0;
        scanf("%d", &N);
        int ans = 0;
        map<int, int> ma;
        for (int i = 0; i < N; i++)
        {
            scanf("%d", &temp);
            for (int j = 31; j >= 0; j--)
                if (temp & (1 << j))
                {
                    ans += ma[j];
                    ma[j]++;
                    break;
                }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int num[100011];
int main(){
    int T,N;
    long long int ans;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&N);
        if(N==1)
            printf("0\n");
        else{
            ans=(N*(N-1))/2;
            for(int i=0;i<N;i++)
                scanf("%d",&num[i]);
            for(int i=0;i<N;i++)
                for(int j=i+1;j<N;j++)
                    if(i==j)
                        continue;
                    else if((num[i]&num[j])<(num[i]^num[j]))
                        ans--;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int temp, T, N;
long long int ans;
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &N);
        int ans = 0;
        map<int, int> ma;
        for (int i = 0; i < N; i++)
        {
            scanf("%d", &temp);
            for (int j = 31; j >= 0; j--)
                if (temp & (1 << j))
                {
                    ans += ma[j];
                    ma[j]++;
                    break;
                }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int num[100011];
int main(){
    int T,N;
    long long int ans;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&N);
        if(N==1)
            printf("0\n");
        else{
            int ans=0;
            map<int,int>ma;
            for(int i=0;i<N;i++){
                scanf("%d",&num[i]);
                int temp=0;
                while(num[i]!=0){
                    num[i]=num[i]>>1;
                    temp++;
                }
                ma[temp]++;
            }
            for(map<int,int>::iterator it=ma.begin();it!=ma.end();it++)
                if(it->second>1)
                    ans+=(it->second)*(it->second-1)/2;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int temp;
int main(){
    int T,N;
    long long int ans;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&N);
        if(N==1)
            printf("0\n");
        else{
            int ans=0;
            map<int,int>ma;
            for(int i=0;i<N;i++){
                scanf("%d",&temp);
                for(int j=31;j>=0;j--)
                    if(temp&(1<<j)){
                        ma[j]++;
                        break;
                    }
            }
            for(map<int,int>::iterator it=ma.begin();it!=ma.end();it++){
                ans+=it->second*(it->second-1)/2;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int temp, T, N;
long long int ans;
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        ans=0;
        scanf("%d", &N);
        map<int, int> ma;
        for (int i = 0; i < N; i++)
        {
            scanf("%d", &temp);
            for (int j = 31; j >= 0; j--)
                if (temp & (1 << j))
                {
                    ans += ma[j];
                    ma[j]++;
                    break;
                }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

vector<ll> pow2;

void solve(){
    ll n, ans=0;
    cin>>n;
    vector<ll> list;
    for(int i=1;i<=n;i++){
        ll temp;
        cin>>temp;
        list.push_back(temp);
    }

    sort(list.begin(), list.end());

    // for(int i=0;i<list.size();i++){
    //     cout<<list[i]<<endl;
    // }

    ll begin=0, end=-1, flag;
    for(int i=0;i<pow2.size();i++){
        if(list[begin]<pow2[i]){
            flag=i;
            break;
        }
    }
    //cout<<flag<<endl;
    while(begin<n){
        for(int i=begin;list[i]<pow2[flag] && i<n;i++){
            end=i;
        }

        ll dis=end-begin+1;
        ans+=dis*(dis-1)/2;

        for(int i=flag+1;i<pow2.size();i++){
            if(list[begin]<pow2[i]){
                flag=i;
                break;
            }
        }
        begin=end+1;
        end=-1;
    }

    cout<<ans<<endl;
}

int main(){
    int t;
    cin>>t;

    ll pow=1;
    while(true){
        pow*=2;
        pow2.push_back(pow);
        if(pow>1e9) break;
    }

    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

vector<ll> pow2;

void solve(){
    ll n, ans=0;
    cin>>n;
    vector<ll> list;
    for(int i=1;i<=n;i++){
        ll temp;
        cin>>temp;
        list.push_back(temp);
    }

    sort(list.begin(), list.end());

    // for(int i=0;i<list.size();i++){
    //     cout<<list[i]<<endl;
    // }

    ll begin=0, end=-1, flag;
    for(int i=0;i<pow2.size();i++){
        if(list[begin]<pow2[i]){
            flag=i;
            break;
        }
    }
    //cout<<flag<<endl;
    while(begin<n){
        for(int i=begin;list[i]<pow2[flag] && i<n;i++){
            end=i;
        }

        for(int i=begin;i<end;i++){
            for(int j=i+1;j<=end;j++){
                if((list[i] & list[j]) >= (list[i] ^ list[j])) ans++;
            }
        }

        for(int i=flag+1;i<pow2.size();i++){
            if(list[begin]<pow2[i]){
                flag=i;
                break;
            }
        }
        begin=end+1;
        end=-1;
    }

    cout<<ans<<endl;
}

int main(){
    int t;
    cin>>t;

    ll pow=1;
    while(true){
        pow*=2;
        pow2.push_back(pow);
        if(pow>1e9) break;
    }

    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

vector<ll> pow2;

void solve(){
    ll n, ans=0;
    cin>>n;
    vector<ll> list;
    for(int i=1;i<=n;i++){
        ll temp;
        cin>>temp;
        list.push_back(temp);
    }

    sort(list.begin(), list.end());

    // for(int i=0;i<list.size();i++){
    //     cout<<list[i]<<endl;
    // }

    ll begin=0, end=-1, flag;
    for(int i=0;i<pow2.size();i++){
        if(list[begin]<pow2[i]){
            flag=i;
            break;
        }
    }
    //cout<<flag<<endl;
    while(begin<n){
        for(int i=begin;list[i]<pow2[flag] && i<n;i++){
            end=i;
        }

        for(int i=begin;i<end;i++){
            for(int j=i+1;j<=end;j++){
                if(list[i]<=list[j]) ans++;
            }
        }

        for(int i=flag+1;i<pow2.size();i++){
            if(list[begin]<pow2[i]){
                flag=i;
                break;
            }
        }
        begin=end+1;
        end=-1;
    }

    cout<<ans<<endl;
}

int main(){
    int t;
    cin>>t;

    ll pow=1;
    while(true){
        pow*=2;
        pow2.push_back(pow);
        if(pow>1e9) break;
    }

    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}