// maximise the multiples
// 11 question answer :maximize multiples
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int maximizeMultiples(int n, int m, int k, vector<int>& arr) {
int maxMultiples = 0;
for(int i = 0; i < n; i++) {
if(arr[i] % m == 0) {
maxMultiples++;
} else {
int diff = m * ceil((double)arr[i] / m) - arr[i];
int res1 = diff;
if(res1 <= k) {
arr[i] += diff;
k -= diff;
if(arr[i]%m==0)
maxMultiples ++;
else break;
}
}
}
return maxMultiples;
}
int main() {
int n;
int m;
int k;
cin >> n >> m >> k;
vector<int> arr(n);
for(int i = 0; i < n; ++i) {
cin >> arr[i];
}
int result = maximizeMultiples(n, m, k, arr);
cout << result << endl;
return 0;
}
// Question 12: Toy shop problem
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Shop {
int coord;
int toys;
};
int getMaxToys(vector<Shop> &shops, int p, int k) {
int n = shops.size();
vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0));
sort(shops.begin(), shops.end(), [](const Shop &a, const Shop &b) {
return a.coord < b.coord;
});
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
int distance = abs(shops[i - 1].coord - p);
if (distance <= j) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - distance] + shops[i - 1].toys);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[n][k];
}
int main() {
int t;
cin >>t;
while(t--)
{
int n, p, k;
cin >> n >> p >> k;
vector<Shop> shops(n);
for (int i = 0; i < n; ++i) {
cin >> shops[i].coord >> shops[i].toys;
}
int result = getMaxToys(shops, p, k);
cout << result << endl;
}
return 0;
}