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<bits/stdc++.h>
#define ci const int&
#define TOT(tc,ql,qr) ((qr>=0?s[qr][tc]:0)-(ql>0?s[ql-1][tc]:0))
using namespace std;
struct elem{
	int l,r;
	long long num;
};
int T,n,C,Q,p[30010],li[30010][5],ri[30010][5],l,r,mid,qi,nc,ni,opl[5],opr[5],sz;
long long qj,s[120010][5];
vector<elem>L[5],tl[30010][5],tr[30010][5];
bool cmp(elem x,elem y){
	return p[x.r]<p[y.r];
}
long long NUM(ci x,ci op){
	if(op==0)return 1;
	if(x<op)return 0;
	if(op==1)return x;
	if(op==2)return x*(x-1)>>1;
	if(op==3)return 1ll*x*(x-1)*(x-2)/6;
	return 1ll*x*(x-1)*(x-2)*(x-3)/24;
}
long long Calc(ci x,ci op){
	long long ret=0;
	for(int i=0;i<=op;++i)ret+=NUM(x-1,i);
	return ret;
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&C,&Q);
		for(int i=1;i<=4;++i)vector<elem>().swap(L[i]),ri[n+1][i]=0;
		for(int i=1;i<=n;++i){
			scanf("%d",&p[i]);
			for(int j=1;j<=C;++j)vector<elem>().swap(tl[i][j]),vector<elem>().swap(tr[i][j]);
		}
		for(int c=1;c<=C;++c){
			tl[n][c].push_back((elem){n+1,n+1,1});
			for(int i=n-1;i>=1;--i){
				for(int j=i+1;j<=i+c&&j<=n;++j)p[j]<p[i]?tl[i][c].push_back((elem){i,j,Calc(n-j,c-(j-i))}):tr[i][c].push_back((elem){i,j,Calc(n-j,c-(j-i))});
				if(tl[i][c].size())sort(tl[i][c].begin(),tl[i][c].end(),cmp);
				if(tr[i][c].size())sort(tr[i][c].begin(),tr[i][c].end(),cmp);
				li[i+1][c]=tl[i][c].size(),ri[i+1][c]=li[i+1][c]+ri[i+2][c]+tr[i+1][c].size();
			}
			li[1][c]=0,ri[1][c]=ri[2][c]+tr[1][c].size();
			for(int i=2;i<=n;++i)li[i][c]+=li[i-1][c],ri[i][c]+=li[i-1][c];
			for(int i=1;i<=n;++i)for(int j=0;j<tl[i][c].size();++j)L[c].push_back(tl[i][c][j]);
			for(int i=n;i>=1;--i)for(int j=0;j<tr[i][c].size();++j)L[c].push_back(tr[i][c][j]);
			s[0][c]=L[c][0].num;
			for(int i=1;i<L[c].size();++i)s[i][c]=s[i-1][c]+L[c][i].num;
		}
		while(Q--){
			scanf("%d%lld",&qi,&qj),nc=C,sz=0,ni=1;
			if(qj>Calc(n,C)){
				puts("-1");
				goto Skip;
			}
			while(nc&&ni<=n){
				l=li[ni][nc],r=ri[ni][nc];
				while(l<r)mid=l+r>>1,TOT(nc,li[ni][nc],mid)>=qj?r=mid:l=mid+1;
				++sz,qj-=TOT(nc,li[ni][nc],l-1),opl[sz]=L[nc][l].l,opr[sz]=L[nc][l].r,ni=opr[sz]+1,nc-=L[nc][l].r-L[nc][l].l;
			}
			for(int i=1;i<=sz;++i)if(opl[i]<=qi&&qi<=opr[i]){
				printf("%d\n",p[opl[i]+opr[i]-qi]);
				goto Skip;
			}
			printf("%d\n",p[qi]);
			Skip:;
		}
	}
	return 0;
}