1
10 2 20
8 5 2 4 10 3 9 7 1 6
5 10
3 17
6 31
3 46
10 42
7 19
9 36
7 3
3 13
8 32
10 25
9 34
10 34
6 33
3 9
2 17
4 5
10 44
9 15
5 40
 1
47 1 47
40 45 19 10 44 33 47 12 2 46 16 23 3 14 21 28 31 42 22 18 35 38 24 25 36 32 4 34 5 20 37 39 6 9 1 7 29 8 17 27 30 11 13 41 15 43 26
39 25
41 24
32 30
10 6
30 13
24 35
41 17
31 31
9 44
21 8
43 23
8 5
29 13
8 4
47 20
22 10
37 27
17 39
43 23
14 42
46 19
43 24
30 31
24 35
31 13
31 32
20 9
3 2
20 9
14 7
7 3
21 36
32 30
47 19
11 43
6 2
31 31
26 12
47 20
2 1
40 24
16 40
45 21
36 28
36 28
17 38
30 31
 1
1 1 4
1
1 1
1 2
1 3
1 4
 1
10 1 1
10 4 6 5 7 9 8 1 3 2
6 10

3
2
7
10
6
7
7
7
5
1
6
6
1
9
4
4
4
1
1
3
 27
27
37
16
20
24
11
20
46
35
11
2
34
47
26
24
7
28
11
3
26
13
37
24
37
37
22
10
22
14
47
38
37
43
23
33
20
4
26
19
30
21
43
1
1
42
37
 1
-1
-1
-1
 9

#include<bits/stdc++.h>
typedef long long LL;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=3e4+9,maxc=5;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
LL T,n,C,q;
LL p[maxn],dl[maxn],dr[maxn],sumw[maxc][(maxn*maxc<<1)+10];
pii range[maxc][maxn];
struct node{
	LL l,r,w;
	bool opt < (const node A)const{
		return p[r]<p[A.r];
	}
};
node L[maxc][(maxn*maxc<<1)+10];
LL Comb(LL N,LL M){
	if(N==M) return 1;
	if(N<M) return 0;
	LL ret(1);
	for(LL i=1;i<=M;++i) ret*=(N-i+1);
	for(LL i=1;i<=M;++i) ret/=i;
	//printf("%lld,%lld:%lld\n",N,M,ret);
	return ret;
}
LL Way(LL len,LL c){
	//printf("(%lld,%)")
	LL ret(1);
	for(LL i=1;i<=c;++i) ret+=Comb(len-1,i);
	return ret;
}
node F(LL i,LL c,LL w){
	LL l(range[c][i].first),r(range[c][i].second),nw(l-1);
	//printf("(%lld,%lld):(%lld,%lld)\n",c,i,l-dl[c]+1,r-dl[c]+1);
	LL v(sumw[c][range[c][i].first-1]);
	while(l<=r){
		LL mid(l+r>>1);
		if(sumw[c][mid]-v<w){
			nw=mid; l=mid+1;
		}else r=mid-1;
	}
	node tmp(L[c][nw+1]); tmp.w=sumw[c][nw]-v;
	return tmp;
}
void Init(){
	for(LL c=0;c<=C;++c){
		dl[c]=maxn*maxc+5; dr[c]=maxn*maxc+4;
		L[c][++dr[c]]=(node){n,n,1};
		range[c][n]=pii(dl[c],dr[c]);
		for(LL i=n-1;i>=1;--i){
			LL _l(0),_r(0);
			for(LL len=1;len<=std::min(c,n-i);++len){
				LL j(i+len);
				if(p[j]<p[i]){
					++_l;
					L[c][dl[c]-_l]=(node){i,j,Way(n-j,c-len)};
				}else{
					++_r;
					L[c][dr[c]+_r]=(node){i,j,Way(n-j,c-len)};
				}
			}
			if(_l){
                std::sort(L[c]+dl[c]-_l,L[c]+dl[c]);
				dl[c]-=_l;
			}
			if(_r){
				std::sort(L[c]+dr[c]+1,L[c]+dr[c]+_r+1);
				dr[c]+=_r;
			}
			range[c][i]=pii(dl[c],dr[c]);
		}
		sumw[c][dl[c]-1]=0;
		for(LL i=dl[c];i<=dr[c];++i){
			sumw[c][i]=sumw[c][i-1]+L[c][i].w;
		}
		/*
		for(LL i=dl[c];i<=dr[c];++i){
			printf("(%lld,%lld,%lld)",L[c][i].l,L[c][i].r,L[c][i].w);
		}
		puts("");
		*/
	}
}
int main(){
	T=Read();
	while(T--){
		n=Read(); C=Read(); q=Read();
		for(LL i=1;i<=n;++i) p[i]=Read();
		Init();
		//puts("033");
		while(q--){
            LL pos1(Read()),pos2(Read());
			if(pos2>sumw[C][dr[C]]){
				puts("-1"); continue;
			}
			LL pos(1);
			LL c(C);
			std::vector<node> suq;
			while(true){
				node tmp(F(pos,c,pos2));
				suq.pb(tmp);
				//printf("(%lld,%lld:%lld)\n",tmp.l,tmp.r,tmp.w);
				//if(!tmp.l) exit(0);
				pos2-=tmp.w;
				c-=tmp.r-tmp.l;
				pos=tmp.r+1;
				if(pos>n || !pos2) break;
			}
			LL flag(0);
            for(LL i=0;i<suq.size();++i){
				LL l(suq[i].l),r(suq[i].r);
				if(l<=pos1 && pos1<=r){
					printf("%lld\n",p[r-(pos1-l)]);
					flag=1;
					break;
				}
			}
			if(!flag){
				printf("%lld\n",p[pos1]);
			}
		}
	}
}