1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4.  
  5. int singificant_bit_position(int x)
  6. {
  7. int pos = 0;
  8. while (x != 0)
  9. {
  10. x /= 2;
  11. ++pos;
  12. }
  13. return pos;
  14. }
  15.  
  16. void mainSolve()
  17. {
  18. int n;
  19. cin >> n;
  20. vector<ll> v(n);
  21. for (int i = 0; i < n; i++)
  22. cin >> v[i];
  23.  
  24. unordered_map<ll, ll> m;
  25. for (int x : v)
  26. ++m[singificant_bit_position(x)];
  27.  
  28. ll ans = 0;
  29. for (auto it : m)
  30. {
  31. ans = (ans + (it.second * (it.second - 1ll)) / 2ll);
  32. }
  33. cout << ans << endl;
  34. }
  35.  
  36. int main()
  37. {
  38. int t;
  39. cin >> t;
  40. while (t--)
  41. {
  42. mainSolve();
  43. }
  44. return 0;
  45. }