Problem: Alice had a permutation p_1, p_2, …, p_n. Unfortunately, the permutation looked very boring, so she decided to change it and choose some non-overlapping subranges of this permutation and reverse them. The cost of reversing a single subrange [l, r] (elements from position l to position r, inclusive) is equal to r - l, and the cost of the operation is the sum of costs of reversing individual subranges. Alice had an integer c in mind, so she only considered operations that cost no more than c.

Then she got really bored, and decided to write down all the permutations that she could possibly obtain by performing exactly one operation on the initial permutation. Of course, Alice is very smart, so she wrote down each obtainable permutation exactly once (no matter in how many ways it can be obtained), and of course the list was sorted lexicographically.

Now Bob would like to ask Alice some questions about her list. Each question is in the following form: what is the i-th number in the j-th permutation that Alice wrote down? Since Alice is too bored to answer these questions, she asked you to help her out.

Input

The first line contains a single integer t (1 ≤ t ≤ 30) — the number of test cases.

The first line of each test case contains three integers n, c, q (1 ≤ n ≤ 3 ⋅ 10^4, 1 ≤ c ≤ 4, 1 ≤ q ≤ 3 ⋅ 10^5) — the length of the permutation, the maximum cost of the operation, and the number of queries.

The next line of each test case contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, p_i ≠ p_j if i ≠ j), describing the initial permutation.

The following q lines describe the queries. Each of them contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ 10^{18}), denoting parameters of this query.

It is guaranteed that the sum of values n over all test cases does not exceed 3 ⋅ 10^5, and the sum of values q over all test cases does not exceed 3 ⋅ 10^5.

Output

For each query output the answer for this query, or -1 if j-th permutation does not exist in her list.

Examples

Input


2
3 1 9
1 2 3
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
6 4 4
6 5 4 3 1 2
1 1
3 14
1 59
2 6


Output


1
2
3
1
3
2
2
1
3
1
4
-1
5


Input


1
12 4 2
1 2 3 4 5 6 7 8 9 10 11 12
2 20
2 21


Output


2
2

Note

In the first test case, Alice wrote down the following permutations: [1, 2, 3], [1, 3, 2], [2, 1, 3].

Note that, for a permutation [3, 2, 1] Alice would have to reverse the whole array, and it would cost her 2, which is greater than the specified value c=1. The other two permutations can not be obtained by performing exactly one operation described in the problem statement.

Solution (in CPP):

Solution:
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MAXN = 30000;
const int MAXCOST = 4;
const int MAXQ = 300000;

int n, mxcost, nq;
int p[MAXN];
int qpos[MAXQ]; ll qperm[MAXQ]; int qans[MAXQ];

vector<int> opt[MAXCOST + 1][MAXN];
ll ways[MAXCOST + 1][MAXN + 1];
ll offset[MAXCOST + 1][MAXN + 1];
map<ll, pair<int, int>> nxt[MAXCOST + 1];


void safeinc(ll& a, ll b) { if (a > LLONG_MAX - b) a = LLONG_MAX; else a += b; }

void solve() {
	REPE(c,mxcost) REP(i, n) {
		opt[c][i].clear();
		for (int j = i; j < n && j <= i + c; ++j) opt[c][i].PB(j);
		sort(opt[c][i].begin(), opt[c][i].end(), [&](const int& a, const int& b) { return p[a] < p[b]; });
	}
	REPE(c, mxcost) {
		ways[c][n] = 1;
		for (int i = n - 1; i >= 0; --i) {
			ways[c][i] = 0;
			for (int j : opt[c][i]) safeinc(ways[c][i], ways[c - (j - i)][j + 1]);
		}
		//printf("ways%d:", c); REP(i, n) printf(" %lld", ways[c][i]); puts("");
	}
	REPE(c, mxcost) {
		nxt[c].clear();
		ll at = 0;
		REP(i, n) {
			offset[c][i] = at;
			ll to = -1;
			for (int j : opt[c][i]) {
				if (j == i) {
					to = at;
				} else {
					nxt[c][at] = MP(i, j);
				}
				safeinc(at, ways[c - (j - i)][j + 1]);
			}
			assert(to != -1); at = to;
		}
		offset[c][n] = at;
		nxt[c][at] = MP(n, n);
		nxt[c][ways[c][0]] = MP(-1, -1);
		//printf("nxt%d:", c); for (auto it = nxt[c].begin(); it != nxt[c].end(); ++it) printf(" %lld:%d/%d", it->first, it->second.first, it->second.second); puts("");
	}

	REP(i, nq) {
		int c = mxcost; ll want = qperm[i]; int pos = qpos[i];
		//printf("processing %d: %lld\n", i, want);
		if (want >= ways[c][0]) { qans[i] = -1; continue; }
		vector<pair<int, int>> revs;
		while (true) {
			auto it = prev(nxt[c].upper_bound(want));
			int at = it->second.first, to = it->second.second;
			want -= it->first;
			if (at == n && to == n) { assert(want == 0); break; }
			//printf("\t(%d,%d)\n", at, to);
			revs.PB(MP(at, to));
			int nc = c - (to - at);
			assert(offset[nc][to + 1] != LLONG_MAX);
			c = nc, want += offset[nc][to + 1];
		}
		if (SZ(revs) == 0) { qans[i] = p[pos]; continue; }
		if (pos < revs[0].first) qans[i] = p[pos];
		FORSZ(j, 1, revs) if (pos > revs[j - 1].second && pos < revs[j].first) qans[i] = p[pos];
		if (pos > revs[SZ(revs) - 1].second) qans[i] = p[pos];
		REPSZ(j, revs) { int a = revs[j].first, b = revs[j].second; if (a <= pos && pos <= b) qans[i] = p[a + (b - pos)]; }
	}

}

void run() {
	scanf("%d%d%d", &n, &mxcost, &nq);
	REP(i, n) scanf("%d", &p[i]), --p[i];
	REP(i, nq) scanf("%d%lld", &qpos[i], &qperm[i]), --qpos[i], --qperm[i];
	solve();
	REP(i, nq) printf("%d\n", qans[i] == -1 ? -1 : qans[i] + 1);
}

void stress() {
	REP(rep, 10000) {
		n = MAXN;
		mxcost = MAXCOST; // rnd() % (MAXCOST + 1);
		nq = MAXQ;
		REP(i, n) p[i] = i;
		//REP(i, n) { int idx = rnd() % (i + 1); swap(p[i], p[idx]); }
		REP(i, nq) qpos[i] = rnd() % n, qperm[i] = (ll)(rnd() % 1000000000) * 1000000000 + rnd() % 1000000000;
		solve();
		printf(".");
	}
}

int main() {
	int ncase; scanf("%d", &ncase); FORE(i, 1, ncase) run();
	//stress();
	return 0;
}