#include <cstdio>
#include <vector>
#include <set>

#if 0
#define dbg(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#else
#define dbg(...)
#endif

using namespace std;

class FenwickTree {
    vector <int> tree;
    int n;
public:
    FenwickTree(int maxN) : n(maxN) {
        tree.assign(n + 1, 0);
    }

    int get(int x) {
        int res = 0;
        while (x >= 0) {
            res += tree[x];
            x = (x & (x + 1)) - 1;
        }
        return res;
    }

    void add(int L, int R, int d) {
        dbg("add(L = %d, R = %d, d = %d)\n", L, R, d);
        add(L, d);
        add(R + 1, -d);
    }
private:
    void add(int x, int d) {
        while (x <= n) {
            tree[x] += d;
            x |= (x + 1);
        }
    }
};

void solve() {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    vector < vector <int> > pos(m);
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        pos[a - 1].push_back(i + 1);
    }

    FenwickTree tree(n + 1);
    tree.add(1, n, k);

    int card;
    set <int> plays;
    for (card = 0; card < m; ++card) {
        bool ok = false;
        for (int i = 0; !ok && i < int(pos[card].size()); ++i) {
            int curPos = pos[card][i];
            if (tree.get(curPos) > 0) {
                dbg("play %d from pos %d\n", card, curPos);
                set <int>::iterator it = plays.upper_bound(-curPos);
                int L = it == plays.end() ? 1 : -(*it) + 1;
                tree.add(L, curPos, -1);
                if (L > 1) {
                    plays.erase(-(L - 1));
                }
                plays.insert(-curPos);
                ok = true;
            }
        }
        if (!ok) {
            break;
        }
    }
    printf("%d\n", card);
}

int main() {
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);

    int tt;
    scanf("%d", &tt);
    for (int ii = 0; ii < tt; ++ii) {
        solve();
    }
    
    return 0;
}