// https://www.geeksforgeeks.org/kth-largest-element-in-a-stream/
#include <iostream>
using namespace std;
void MaxHeapify(int a[], int n, int i) {
int l= 2*i+1, r= 2*i+2, largest = i;
if (l<n) {
if (a[l] > a[largest])
largest= l;
if (r<n && a[r] > a[largest])
largest = r;
if (largest != i) {
swap (a[i], a[largest]);
MaxHeapify(a, n, largest);
}
}
}
int extractMax(int b[], int n, int k) {
int s;
for (int i=0; i<k; i++) {
s=b[0];
b[0]=b[n-1-i];
MaxHeapify(b, n-i, 0);
}
return s;
}
void kLargest (int a[], int n, int k) {
for (int i=0; i<k-1;i++)
cout<< -1 << " ";
for (int i=k-1; i<n; i++) {
int b[i+1];
copy (a, a+i+1, b); //keep cropping the array and find the kth largest element in the resultant array.
for (int j= (i-1)/2; j>=0; j--) //Create the Max Heap from the resultant array to use it in extract min
MaxHeapify(b, i+1, j);
int s = extractMax(b,i+1,k);
cout<< s << " ";
}
}
int main() {
int t;
cin>>t;
while (t-->0) {
int n, k;
cin>> k>> n;
int a[n];
for (int i=0; i<n; i++)
cin>> a[i];
kLargest (a, n, k);
cout<< "\n";
}
}