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<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<bitset>
#include<cstdio>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=1e5+7;
const int INF=1e9+7;
int T,n,c,q;
int p[N];
ll f[N][5],L[N][5],R[N][5],l[5],r[5];
int id[N][5];
bool cmp(int x,int y){return p[x]<p[y];}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&c,&q);
		rep(i,n)scanf("%d",&p[i]);
		rep(i,n+10)rep0(j,c+1)f[i][j]=0;
		rep0(i,c+1)f[n+1][i]=1;
		for(int i=n;i;i--){
			rep0(j,c+1){
				f[i][j]=f[i+1][j];
				rep(k,j){
					if(i+k>n)break;
					f[i][j]+=f[i+k+1][j-k];
				}
			}
		}
		rep(i,n){
			rep0(j,c+1)id[i][j]=i+j;
			sort(id[i],id[i]+c+1,cmp);
		}
		rep0(i,c+1){
			L[1][i]=1;
			R[1][i]=f[1][i];
			rep(j,n){
				ll k,vl=0,vr=0;
				for(k=0;id[j][k]!=j;k++)if(id[j][k]-j<=i)vl+=f[id[j][k]+1][i-id[j][k]+j];
				for(k++;k<=c;k++)if(id[j][k]-j<=i)vr+=f[id[j][k]+1][i-id[j][k]+j];
				L[j+1][i]=L[j][i]+vl;
				R[j+1][i]=R[j][i]-vr;
			}
		}
		while(q--){
			int x,cnt=0,w=1,o=c; ll v; scanf("%d%I64d",&x,&v);
			if(v>f[1][c]){
				puts("-1");
				continue;
			}
			while(1){
				if(L[n+1][o]-L[w][o]+1ll<=v&&v<=R[n+1][o]-L[w][o]+1ll)break;
				int a=w,b=n,g;
				while(a<b-1){
					int mid=(a+b)>>1;
					if(L[mid+1][o]-L[w][o]+1ll<=v&&v<=R[mid+1][o]-L[w][o]+1ll)a=mid;
					else b=mid;
				}
				if(L[a+1][o]-L[w][o]+1ll>v||v>R[a+1][o]-L[w][o]+1ll)g=a;
				else g=b;
				if(v<L[g+1][o]-L[w][o]+1){
					v-=(L[g][o]-L[w][o]);
					for(int k=0;id[g][k]!=g;k++){
						if(id[g][k]-g<=o){
							if(v>f[id[g][k]+1][o-id[g][k]+g])v-=f[id[g][k]+1][o-id[g][k]+g];
							else{
								w=id[g][k]+1;
								o=o-id[g][k]+g;
								l[cnt]=g;
								r[cnt++]=id[g][k];
								break;
							}
						}
					}
				}
				else{
					v-=(R[g+1][o]-L[w][o]+1);
					int k=0;
					for(;id[g][k]!=g;k++);
					for(k++;k<=c;k++){
						if(id[g][k]-g<=o){
							if(v>f[id[g][k]+1][o-id[g][k]+g])v-=f[id[g][k]+1][o-id[g][k]+g];
							else{
								w=id[g][k]+1;
								o=o-id[g][k]+g;
								l[cnt]=g;
								r[cnt++]=id[g][k];
								break;
							}
						}
					}
				}
			}
			int Ans=p[x];
			rep0(i,cnt)if(l[i]<=x&&r[i]>=x)Ans=p[l[i]+r[i]-x];
			printf("%d\n",Ans);
		}
	}
	return 0;
}
