for _ in range(int(input())):
n , c = map(int,input().split())
s=list(map(int,input().split()))
t=[]
i=0
while len(s)!=0:
t.append(s.count(s[i]))
s=list(filter((s[i]).__ne__,s))
count=0
for j in range(len(t)):
if c<t[j]:
count+=c
else:
count+=t[j]
print(count)
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int tt;
cin >> tt;
while (tt--) {
int n, c;
cin >> n >> c;
vector<int> arr(101);
for (int i = 0; i < n; ++i) {
int v; cin >> v;
arr[v]++;
}
int result = 0;
for (auto v : arr) result += min(v, c);
cout << result << endl;
}
return 0;
}
/* Try this if you are stuck:
1) Maybe binary search on answer?
2) Try solving it in reverse
3) Think of a simple problem
4) Think of elements which are special
(like minimum, maximum, deepest node in tree, root)
5) Is it graph problem?
*/
/* DONT FORGET:
EDGE CASES!!!!!
N = 1,2...
LONG LONG INSTEAD OF INT??
*/
1547C - Pair Programming | 550A - Two Substrings |
797B - Odd sum | 1093A - Dice Rolling |
1360B - Honest Coach | 1399C - Boats Competition |
1609C - Complex Market Analysis | 1657E - Star MST |
1143B - Nirvana | 1285A - Mezo Playing Zoma |
919B - Perfect Number | 894A - QAQ |
1551A - Polycarp and Coins | 313A - Ilya and Bank Account |
1469A - Regular Bracket Sequence | 919C - Seat Arrangements |
1634A - Reverse and Concatenate | 1619C - Wrong Addition |
1437A - Marketing Scheme | 1473B - String LCM |
1374A - Required Remainder | 1265E - Beautiful Mirrors |
1296A - Array with Odd Sum | 1385A - Three Pairwise Maximums |
911A - Nearest Minimums | 102B - Sum of Digits |
707A - Brain's Photos | 1331B - Limericks |
305B - Continued Fractions | 1165B - Polycarp Training |