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:
//#pragma GCC target("avx,avx2")	
#include<bits/stdc++.h>
//#include<immintrin.h>
using namespace std;

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef int64_t s64;
typedef uint64_t u64;
typedef uint32_t u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
char readc()
{
	char c;
	while(isspace(gc));
	return c;
}
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int C=5,N=3e4+5;
s64 dp[C][N],sum[C][N],sum1[C][N];
int p[N];
vector<int>lk[N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	rep(c,0,4)
	{
		dp[c][0]=1;
		rep(n,1,30000)
		rep(i,0,min(n-1,c))dp[c][n]+=dp[c-i][n-i-1];
	}
	int tt=read();
	while(tt--)
	{
		int n=read(),c=read(),q=read();
		rep(i,1,n)p[i]=read();
		per(i,n,1)
		{
			lk[i].clear();
			rep(j,0,c)
			{
				if(i+j<=n)lk[i].push_back(j);
				sort(lk[i].begin(),lk[i].end(),[&](int x,int y){return p[i+x]<p[i+y];});
			}
		}
		rep(i,1,n)
		{
			rep(j,0,c)
			{
				sum[j][i]=sum[j][i-1];
				rep(k,0,j)
				if(i+k<=n && p[i+k]<p[i])sum[j][i]+=dp[j-k][n-i-k];
				sum1[j][i]=sum[j][i]+dp[j][n-i];
			}
		}
		while(q--)
		{
			int query_i=read();
			s64 k;
			scanf("%lld",&k);
			if(k>dp[c][n])
			{
				puts("-1");
				continue;
			}
			int i=1,nc=c;
			while(i<=n)
			{
				int j=0;
				s64 now;
				while(1)
				{
					while(lk[i][j]>nc)++j;
					if(k<=(now=dp[nc-lk[i][j]][n-i-lk[i][j]]))break;
					k-=now;
					++j;
				}
				nc-=lk[i][j];
				int i1=i+lk[i][j];
				if(i1>=query_i)
				{
					printf("%d\n",p[i+i1-query_i]);
					break;
				}
				i=i1+1;
				i1=min(lower_bound(sum[nc]+i,sum[nc]+n,k+sum[nc][i-1])-sum[nc],
				lower_bound(sum1[nc]+i,sum1[nc]+n,k+sum[nc][i-1]-1,greater<s64>())-sum1[nc]);
				if(i1>query_i)
				{
					printf("%d\n",p[query_i]);
					break;
				}
				k-=sum[nc][i1-1]-sum[nc][i-1];
				i=i1;
			}
		}
	}	
}
 
/* stuff you should look for
	* int overflow, array bounds, uppercase/lowercase 
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/