Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);

#define vi vector<int>
#define vc vector<char>
#define vii vector<vector<int>>

#define mii map<int, int>
#define mci map<char, int>
#define mic map<int, char>

#define f(i, a, b) for (int i = (a); i < (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define si set<int>
#define sc set<char>

#ifndef ONLINE_JUDGE
#define debug(x)                                                               \
  cerr << #x << " ";                                                           \
  _print(x);                                                                   \
  cerr << endl;
#else
#define debug(x) ;
#endif

void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(uint64_t t) { cerr << t; }
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T> void _print(multiset<T> v);
template <class T, class V> void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.ff);
  cerr << ",";
  _print(p.ss);
  cerr << "}";
}
template <class T> void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T> void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T> void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V> void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
const int MOD = (int)1e9 + 7;
int binpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b = b >> 1;
  }
  return res;
}

const int MOD2 = 998244353;
const int MAX = 1e5 + 5;
const int INF = 1e9;
const int INFLL = 1e18;
void solve() {
  int n, k;
  cin >> n >> k;
  if (k == n) {
    cout << 1 << endl;
    return;
  }
  vi a(n);
  for (auto &x : a)
    cin >> x;
  mii mp;
  for (int i = 0; i < n; i++) {
    mp[a[i]]++;
  }
  int ans = 0;
  vi b;
  for (auto &x : mp) {
    b.pb(x.second);
  }
  sort(all(b));
  debug(b);
  for (int i = 0; i < b.size(); i++) {
    if (k >= b[i]) {

      k -= b[i];
      b[i] = 0;
    }
  }
  // debug(b);
  for (int i = 0; i < b.size(); i++) {
    if (b[i] > 0)
      ans++;
  }
  cout << ans << endl;
}
signed main() {

#ifndef ONLINE_JUDGE
  freopen("Error.txt", "w", stderr);
#endif
  fastio;

  int t = 1;
  cin >> t;

  while (t--) {
    solve();
  }

  return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);

#define vi vector<int>
#define vc vector<char>
#define vii vector<vector<int>>

#define mii map<int, int>
#define mci map<char, int>
#define mic map<int, char>

#define f(i, a, b) for (int i = (a); i < (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define si set<int>
#define sc set<char>

#ifndef ONLINE_JUDGE
#define debug(x)                                                               \
  cerr << #x << " ";                                                           \
  _print(x);                                                                   \
  cerr << endl;
#else
#define debug(x) ;
#endif

void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(uint64_t t) { cerr << t; }
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T> void _print(multiset<T> v);
template <class T, class V> void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.ff);
  cerr << ",";
  _print(p.ss);
  cerr << "}";
}
template <class T> void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T> void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T> void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V> void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
const int MOD = (int)1e9 + 7;
int binpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b = b >> 1;
  }
  return res;
}

const int MOD2 = 998244353;
const int MAX = 1e5 + 5;
const int INF = 1e9;
const int INFLL = 1e18;
void solve() {
  int n, k;
  cin >> n >> k;
  if (k == n) {
    cout << 1 << endl;
    return;
  }
  vi a(n);
  for (auto &x : a)
    cin >> x;
  mii mp;
  for (int i = 0; i < n; i++) {
    mp[a[i]]++;
  }
  int ans = 0;
  vi b;
  for (auto &x : mp) {
    b.pb(x.second);
  }
  sort(all(b));
 // debug(b);
  for (int i = 0; i < b.size(); i++) {
    if (k >= b[i]) {

      k -= b[i];
      b[i] = 0;
    }
  }
  // debug(b);
  for (int i = 0; i < b.size(); i++) {
    if (b[i] > 0)
      ans++;
  }
  cout << ans << endl;
}
signed main() {

#ifndef ONLINE_JUDGE
  freopen("Error.txt", "w", stderr);
#endif
  fastio;

  int t = 1;
  cin >> t;

  while (t--) {
    solve();
  }

  return 0;
}