#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<cstring>
#include<set>
#include<iterator>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<iomanip>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
struct SegmentTree
{
int lc, rc;
int dat;
}t[N * 50];
int tot, root[N];
int a[N], pos[N];
int ans[N];
int update(int now, int l, int r, int x)
{
int p = ++tot;
t[p] = t[now];
if (l == r)
{
t[p].dat++;
return p;
}
int mid = (l + r) >> 1;
if (x <= mid)
t[p].lc = update(t[now].lc, l, mid, x);
else
t[p].rc = update(t[now].rc, mid + 1, r, x);
t[p].dat = t[t[p].lc].dat + t[t[p].rc].dat;
return p;
}
int build(int l, int r)
{
//cout << l << " " << r << endl;
int p = ++tot;
t[p].dat = 0;
if (l == r)
{
return p;
}
int mid = (l + r) >> 1;
t[p].lc = build(l, mid);
t[p].rc = build(mid + 1, r);
return p;
}
int ask(int p, int q, int l, int r, int L, int R)
{
if (t[p].dat - t[q].dat == 0)
return -1;
if (l == r)
{
if (t[p].dat - t[q].dat)
return l;
return -1;
}
int mid = (l + r) >> 1;
int ret = -1;
if (R > mid)
ret = ask(t[p].rc, t[q].rc, mid + 1, r, L, R);
if (ret == -1 && L <= mid)
ret = ask(t[p].lc, t[q].lc, l, mid, L, R);
return ret;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, k;
scanf("%d%d", &n, &k);
tot = 0;
root[0] = build(1, n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
pos[a[i]] = i;
root[i] = update(root[i - 1], 1, n, a[i]);
}
ans[1] = 1;
for (int i = 2; i <= n; i++)
{
int begin = i;
int cot = 0;
int st = max(1, pos[begin] - k);
int ed = min(n, pos[begin] + k);
begin = ask(root[st - 1], root[ed], 1, n, 1, begin - 1);
//cout << "begin == " << begin << endl;
if (begin == -1)
{
ans[i] = 1;
}
else
{
ans[i] = ans[begin] + 1;
}
}
for (int i = 1; i <= n; i++)
{
if (i != 1)
printf(" ");
printf("%d", ans[i]);
}
printf("\n");
}
return 0;
}