#include<bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt","r",stdin);
    int nTest; cin >> nTest;
    while(nTest--){
        int n, k; cin >> n >> k;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];
        vector<int> r(n);
        for(int i=n-1; i>=0; i--){
            r[i] = i;
            while (r[i]<n-1 && a[r[i] + 1]>=a[i]) r[i] = r[r[i] + 1];
        }
        vector<int> ans(n);
        deque<int> dq;
        for(int i=0; i<n; i++){
            while (dq.size() && (a[dq.back()]>a[i] || r[dq.back()] < i || dq.back()<i-k+1)) dq.pop_back();
            dq.push_front(i);
            ans[i] = a[dq.back()];
        }
        for(int i=k-1; i<n; i++) cout << ans[i] << " ";
        cout << '\n';
    }
    return 0;
}