//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "game"

#ifdef LOCAL
static struct __timestamper {
    string what;
    __timestamper(const char* what) : what(what){};
    __timestamper(const string& what) : what(what){};
	~__timestamper(){
        TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

bool check(const vector<int>& v, int k, int m) {
	vector<bool> used(m);
	int done = 0;
	for (int i = (int)v.size() - 1; i >= 0; i--) {
		if (v[i] >= m) continue;
		if (used[v[i]]) continue;
		if (v[i] >= m - k - done)
			used[v[i]] = true, done++;
	}
	return done == m;
} 

void solve(){
	int n, m, k;
	scanf("%d%d%d",&n,&m,&k);
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		scanf("%d",&v[i]), v[i]--;
	int l = 0;
	int r = m+1;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (check(v, k, mid))
			l = mid;
		else
			r = mid;
	}
	printf("%d\n", l);
}

int main(){
    assert(freopen(TASKNAME".in","r",stdin));
    assert(freopen(TASKNAME".out","w",stdout));
	int t;
	scanf("%d",&t);
	while (t-->0) solve();      
    return 0;
}