import std.stdio;
import std.algorithm;
 

int main() {
	int t;
	scanf("%d", &t);
	while (t --> 0) {
        int n;
		scanf("%d", &n);
		int[] a = new int[n];
        int[] cnt = new int [42];
        long result = 0;
		for (int i = 0; i < n; ++i) {
			scanf("%d", &a[i]);
            int bit_id = 0;
            while (a[i] > 0) {
            	++bit_id;
                a[i] /= 2;
            }
            result += cnt[bit_id];
            ++cnt[bit_id];
		}
		printf("%lld\n", result);
	}
	
	return 0;
}