#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory.h>

using namespace std;

int rmq[1000500], d;
void rput(int i, int a){
	for(i += d; i; i >>= 1)
		rmq[i] = max(rmq[i], a);
}
int rmax(int l, int r){
	int res = 0;
	for(l += d, r += d; l<r; l >>= 1, r >>= 1){
		if(l&1) res = max(res, rmq[l]);
		if(~r&1) res = max(res, rmq[r--]);
	}
	return max(res, rmq[l]);
}
bool cmp(pair<int,int> a, pair<int,int> b){
	return a.first < b.first || (a.first == b.first && a.second > b.second);
}
void solve(){
	int n, a, k;
	scanf("%d%d", &n, &k);
	vector<pair<int,int> > v;
	for(int i=0;i<n;++i){
		scanf("%d", &a);
		v.push_back(make_pair(a, i));
	}
	sort(v.begin(), v.end(), cmp);
	memset(rmq, 0, sizeof(rmq));
	d=1;
	int res=0;
	while(d<n)d<<=1;
	for(int i=0; i<(int)v.size(); ++i){
		int t = rmax(max(v[i].second-k, 0), v[i].second-1) + 1;
		if(t==1 && v[i].second>=k) t=0;
		else{
			rput(v[i].second, t);
			res = max(res, v[i].second);
		}
	}
	cout<<res+1<<endl;
}

int main(){
	freopen("ladder.in", "r", stdin);
	int T;
	scanf("%d", &T);
	while(T--) solve();
	return 0;
}
