#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
unordered_map<int, int> cnt; // 记录每种果子的数量
for (int i = 0; i < n; i++) {
int a;
cin >> a;
cnt[a]++;
}
// 统计每种数量有多少个果子
unordered_map<int, int> freq; // freq[x] = 数量为x的果子总数
for (auto& p : cnt) {
freq[p.second] += p.second;
}
// 处理查询
for (int i = 0; i < q; i++) {
int d;
cin >> d;
if (d > n) {
// 如果天数超过n,所有果子都会被打完
cout << 0 << " ";
continue;
}
// 计算前d天打掉的果子总数
int removed = 0;
for (auto& p : freq) {
if (p.first <= d) {
removed += p.second;
}
}
cout << n - removed << " ";
}
cout << "\n";
}
return 0;
}