1. // Pratiyush Mishra
  2.  
  3. #include <bits/stdc++.h>
  4. #define ll long long int
  5. using namespace std;
  6.  
  7. void mainSolve()
  8. {
  9. int n;
  10. cin >> n;
  11. vector<int> v(n);
  12. for (int i = 0; i < n; i++)
  13. cin >> v[i];
  14. unordered_map<int, int> freq;
  15. for (int x : v)
  16. ++freq[x];
  17. int max_freq = 0;
  18. for (auto it : freq)
  19. max_freq = max(max_freq, it.second);
  20. int ans = n - max_freq;
  21. cout << ans << endl;
  22. }
  23.  
  24. int main()
  25. {
  26. #ifndef ONLINE_JUDGE
  27. freopen("input.txt", "r", stdin);
  28. freopen("output.txt", "w", stdout);
  29. #endif
  30. int t;
  31. cin >> t;
  32. while (t--)
  33. {
  34. mainSolve();
  35. }
  36. return 0;
  37. }