#include <climits>
#include <cstdio>
#include <queue>
using namespace std;
int main()
{
    int T, t, n, x;
    scanf("%d", &T);
    while (T--)
    {
        priority_queue<int, vector<int>, less<int>> q1;
        priority_queue<int, vector<int>, greater<int>> q2;
        q1.push(INT_MAX), q2.push(INT_MIN);
        scanf("%d%d", &t, &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &x);
            if (x > q1.top())
                q1.push(x);
            else
                q2.push(x);
            while (q1.size() > q2.size())
                q2.push(q1.top()), q2.pop();
            while (q2.size() > q1.size())
                q1.push(q2.top()), q1.pop();
            printf("%d ", q1.top());
        }
        putchar('\n');
    }
    return 0;
}