1. #include <bits/stdc++.h>
  2. using namespace std;
  3. /*
  4. ------------------------Input Checker----------------------------------
  5. */
  6. long long readInt(long long l,long long r,char endd){
  7. long long x=0;
  8. int cnt=0;
  9. int fi=-1;
  10. bool is_neg=false;
  11. while(true){
  12. char g=getchar();
  13. if(g=='-'){
  14. assert(fi==-1);
  15. is_neg=true;
  16. continue;
  17. }
  18. if('0'<=g && g<='9'){
  19. x*=10;
  20. x+=g-'0';
  21. if(cnt==0){
  22. fi=g-'0';
  23. }
  24. cnt++;
  25. assert(fi!=0 || cnt==1);
  26. assert(fi!=0 || is_neg==false);
  27. assert(!(cnt>19 || ( cnt==19 && fi>1) ));
  28. } else if(g==endd){
  29. if(is_neg){
  30. x= -x;
  31. }
  32. if(!(l <= x && x <= r))
  33. {
  34. cerr << l << ' ' << r << ' ' << x << '\n';
  35. assert(1 == 0);
  36. }
  37. return x;
  38. } else {
  39. assert(false);
  40. }
  41. }
  42. }
  43. string readString(int l,int r,char endd){
  44. string ret="";
  45. int cnt=0;
  46. while(true){
  47. char g=getchar();
  48. assert(g!=-1);
  49. if(g==endd){
  50. break;
  51. }
  52. cnt++;
  53. ret+=g;
  54. }
  55. assert(l<=cnt && cnt<=r);
  56. return ret;
  57. }
  58. long long readIntSp(long long l,long long r){
  59. return readInt(l,r,' ');
  60. }
  61. long long readIntLn(long long l,long long r){
  62. return readInt(l,r,'\n');
  63. }
  64. string readStringLn(int l,int r){
  65. return readString(l,r,'\n');
  66. }
  67. string readStringSp(int l,int r){
  68. return readString(l,r,' ');
  69. }
  70. /*
  71. ------------------------Main code starts here----------------------------------
  72. */
  73. const int MAX_T = 1e4;
  74. const int MAX_N = 1e5;
  75. const int MAX_SUM_LEN = 1e6;
  76. const int MAX_A = 1e9 ;
  77. #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  78. #define ff first
  79. #define ss second
  80. #define mp make_pair
  81. #define ll long long
  82. #define rep(i,n) for(int i=0;i<n;i++)
  83. #define rev(i,n) for(int i=n;i>=0;i--)
  84. #define rep_a(i,a,n) for(int i=a;i<n;i++)
  85. #define pb push_back
  86. int sum_n = 0;
  87. int max_n = 0;
  88. int yess = 0;
  89. int nos = 0;
  90. int total_ops = 0;
  91. ll mod = 1000000007;
  92.  
  93.  
  94. void solve()
  95. {
  96.  
  97. int n = readIntLn(1, MAX_N);
  98. sum_n+=n;
  99. max_n = max(max_n, n);
  100.  
  101. ll a[n];
  102.  
  103. rep(i,n){
  104. if(i<n-1) a[i] = readIntSp(1, 1e9);
  105. else a[i] = readIntLn(1, 1e9);
  106. }
  107.  
  108.  
  109. vector<ll> cnt(60) ;
  110. for(int i = 0 ; i < n ; i++)
  111. {
  112. for(ll j = 35 ; j >= 0 ; j--)
  113. {
  114. if(((1LL << j) & a[i]) != 0)
  115. {
  116. cnt[j]++ ;
  117. break ;
  118. }
  119. }
  120. }
  121.  
  122. ll ans = 0 ;
  123. for(int i = 0 ; i <= 35 ; i++)
  124. {
  125. ans += ((cnt[i] * (cnt[i]-1))/2) ;
  126. }
  127. cout << ans << endl ;
  128.  
  129. }
  130.  
  131. int main()
  132. {
  133. ios_base::sync_with_stdio(0);
  134. cin.tie(0); cout.tie(0);
  135. #ifndef ONLINE_JUDGE
  136. freopen("inputf.txt" , "r" , stdin) ;
  137. freopen("outputf.txt" , "w" , stdout) ;
  138. freopen("error.txt" , "w" , stderr) ;
  139. #endif
  140. ll t ;
  141. t = readIntLn(1,10000);
  142.  
  143. for(int i=1;i<=t;i++)
  144. {
  145. solve();
  146. }
  147. assert(getchar() == -1);
  148. assert(sum_n<=1000000);
  149. cerr<<"SUCCESS\n";
  150. cerr<<"Sum of lengths : " << sum_n <<'\n';
  151. cerr<<"Maximum length : " << max_n <<'\n';
  152. // cerr<<"Total operations : " << total_ops << '\n';
  153. //cerr<<"Answered yes : " << yess << '\n';
  154. //cerr<<"Answered no : " << nos << '\n';
  155. return 0;
  156. }