#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// State to track Capacity (C) and Remaining Budget (R)
struct State {
    long long C, R;
    
    // Sort descending by C, then descending by R
    bool operator<(const State& o) const {
        if (C != o.C) return C > o.C;
        return R > o.R;
    }
};

void solve() {
    long long n, m, k;
    cin >> n >> m >> k;
    
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    // Initialize the Pareto frontier
    vector<State> frontier;
    frontier.push_back({k, k});

    for (int i = 0; i < n; i++) {
        long long req = (m - a[i]) % m;
        bool can_reach_zero = false;
        
        for (auto& s : frontier) {
            if (s.C >= req) {
                can_reach_zero = true;
                break;
            }
        }

        long long v_min = can_reach_zero ? 0 : a[i];
        vector<State> next_states;

        if (can_reach_zero) {
            for (auto& s : frontier) {
                if (s.C < req) continue;
                
                long long add_prev = s.C - s.R;
                
                // Find largest x1 <= add_prev
                long long x1 = -1;
                if (add_prev >= req) {
                    long long k1 = (add_prev - req) / m;
                    x1 = req + k1 * m;
                }
                
                // Find smallest x2 >= add_prev
                long long x2 = -1;
                if (x1 == add_prev) {
                    x2 = x1;
                } else {
                    x2 = (x1 == -1) ? req : x1 + m;
                }

                // Push valid branch states
                if (x1 != -1 && x1 <= s.C) {
                    next_states.push_back({x1 + s.R, s.R});
                }
                if (x2 != -1 && x2 <= s.C && x2 != x1) {
                    next_states.push_back({s.C, s.C - x2});
                }
            }
        } else {
            // If we can't reach 0, minimum achievable is a[i] via x=0.
            for (auto& s : frontier) {
                next_states.push_back({s.R, s.R});
            }
        }

        // Pareto pruning: retain strictly dominant configurations
        sort(next_states.begin(), next_states.end());
        frontier.clear();
        long long max_R = -1;
        
        for (auto& s : next_states) {
            if (s.R > max_R) {
                frontier.push_back(s);
                max_R = s.R;
            }
        }

        // Safeguard to prevent TLE, capping state space if it ever branches unusually wide.
        if (frontier.size() > 600) {
            vector<State> reduced;
            double step = (double)frontier.size() / 500.0;
            for (double idx = 0; idx < frontier.size(); idx += step) {
                reduced.push_back(frontier[(int)idx]);
            }
            if (reduced.back().C != frontier.back().C || reduced.back().R != frontier.back().R) {
                reduced.push_back(frontier.back());
            }
            frontier = reduced;
        }

        a[i] = v_min;
    }

    // Output sequence
    for (int i = 0; i < n; i++) {
        cout << a[i] << (i == n - 1 ? "" : " ");
    }
    cout << "\n";
}

int main() {
    // Fast I/O
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    if (cin >> t) {
        while (t--) {
            solve();
        }
    }
    return 0;
}