This is the easier version of the problem. In this version $1 \le n, m \le 100$. You can hack this problem only if you solve and lock both problems.

You are given a sequence of integers $a=[a_1,a_2,\dots,a_n]$ of length $n$. Its subsequence is obtained by removing zero or more elements from the sequence $a$ (they do not necessarily go consecutively). For example, for the sequence $a=[11,20,11,33,11,20,11]$:

  $[11,20,11,33,11,20,11]$, $[11,20,11,33,11,20]$, $[11,11,11,11]$, $[20]$, $[33,20]$ are subsequences (these are just some of the long list);  $[40]$, $[33,33]$, $[33,20,20]$, $[20,20,11,11]$ are not subsequences. 

Suppose that an additional non-negative integer $k$ ($1 \le k \le n$) is given, then the subsequence is called optimal if:

  it has a length of $k$ and the sum of its elements is the maximum possible among all subsequences of length $k$;  and among all subsequences of length $k$ that satisfy the previous item, it is lexicographically minimal. 

Recall that the sequence $b=[b_1, b_2, \dots, b_k]$ is lexicographically smaller than the sequence $c=[c_1, c_2, \dots, c_k]$ if the first element (from the left) in which they differ less in the sequence $b$ than in $c$. Formally: there exists $t$ ($1 \le t \le k$) such that $b_1=c_1$, $b_2=c_2$, ..., $b_{t-1}=c_{t-1}$ and at the same time $b_t<c_t$. For example:

  $[10, 20, 20]$ lexicographically less than $[10, 21, 1]$,  $[7, 99, 99]$ is lexicographically less than $[10, 21, 1]$,  $[10, 21, 0]$ is lexicographically less than $[10, 21, 1]$. 

You are given a sequence of $a=[a_1,a_2,\dots,a_n]$ and $m$ requests, each consisting of two numbers $k_j$ and $pos_j$ ($1 \le k \le n$, $1 \le pos_j \le k_j$). For each query, print the value that is in the index $pos_j$ of the optimal subsequence of the given sequence $a$ for $k=k_j$.

For example, if $n=4$, $a=[10,20,30,20]$, $k_j=2$, then the optimal subsequence is $[20,30]$ — it is the minimum lexicographically among all subsequences of length $2$ with the maximum total sum of items. Thus, the answer to the request $k_j=2$, $pos_j=1$ is the number $20$, and the answer to the request $k_j=2$, $pos_j=2$ is the number $30$.


-----Input-----

The first line contains an integer $n$ ($1 \le n \le 100$) — the length of the sequence $a$.

The second line contains elements of the sequence $a$: integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$).

The third line contains an integer $m$ ($1 \le m \le 100$) — the number of requests.

The following $m$ lines contain pairs of integers $k_j$ and $pos_j$ ($1 \le k \le n$, $1 \le pos_j \le k_j$) — the requests.


-----Output-----

Print $m$ integers $r_1, r_2, \dots, r_m$ ($1 \le r_j \le 10^9$) one per line: answers to the requests in the order they appear in the input. The value of $r_j$ should be equal to the value contained in the position $pos_j$ of the optimal subsequence for $k=k_j$.


-----Examples-----
Input
3
10 20 10
6
1 1
2 1
2 2
3 1
3 2
3 3

Output
20
10
20
10
20
10

Input
7
1 2 1 3 1 2 1
9
2 1
2 2
3 1
3 2
3 3
1 1
7 1
7 7
7 4

Output
2
3
2
3
2
3
1
1
3



-----Note-----

In the first example, for $a=[10,20,10]$ the optimal subsequences are:   for $k=1$: $[20]$,  for $k=2$: $[10,20]$,  for $k=3$: $[10,20,10]$.

Difficulty: interview

Starter code:

Solutions:
a = int(input())
Ans = []
A = list(map(int, input().split()))
for i in range(a):
    A[i] = [A[i], -i]
A.sort()
for i in range(a):
    A[i][1] = -A[i][1]
for i in range(int(input())):
    n, m = map(int, input().split())
    B = list(A[a - n:])
    B.sort(key=lambda n: n[1])
    Ans.append(B[m - 1][0])
for an in Ans:
    print(an)

n=int(input())
import copy
mins=[0]*n
a=list(map(int,input().split()))
m=int(input())
for i in range(m):
    f=a.copy()
    k,pos=list(map(int,input().split()))
    for l in range(n-k):
        if mins[l]==0:
            mins[l]=min(f)
        for j in range(len(f)-1,-1,-1):
            if f[j]==mins[l]:
                f.pop(j)
                break
    print(f[pos-1])


n = int(input())
a = list(map(int, input().split()))
m = int(input())
for i in range(m):
    d = dict()
    k, pos = map(int, input().split())
    b = a + []
    for i in range(k):
        d[b.index(max(b))] = max(b)
        b[b.index(max(b))] = 0
    print(d[sorted(d.keys())[pos - 1]])

n = int(input())
c = list(map(lambda x: (int(x[1]),-x[0]),enumerate(input().split())))
so = sorted(c)
for i in range(int(input())):
    k,r = map(int,input().split())
    now = so[-k:]
    now.sort(key = lambda x: -x[1])
    print(now[r-1][0])

n = int(input())
data = input().split()
data1 = []
for i in range(n):
    data1.append((int(data[i]), i))
data1.sort(key=lambda x: (x[0], -x[1]))
for i in range(int(input())):
    k, pos = map(int, input().split())
    temp = sorted(data1[len(data1) - k:], key=lambda x: x[1])
    print(temp[pos - 1][0])

n = int(input())
arr = [int(i) for i in input().split()]

sor = [[arr[i], n - i] for i in range(n)]
sor.sort()

m = int(input())

for i in range(m):
	op = []
	[q, index] = [int(i) for i in input().split()]
	for j in range(q):
		op.append(n - sor[-1-j][1])
	op.sort()
	print(arr[op[index - 1]])


def main():
    n = int(input())
    a = list(enumerate(map(int, (input().split()))))
    a.sort(key = lambda item: (item[1], -item[0]))
    #print(a)
    m = int(input())
    for i in range(m):
        k, pos = map(int, input().split())
        s = a[-k:]
        s = sorted(s)
        print(s[pos - 1][1])

main()

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=[a[i],n-i]
a.sort()
c=list(range(n))
for i in range(n):
  c[n-i-1]=[n-a[i][1]+1,a[i][0]]
m=int(input())
for g in range(m):
  k,pos=list(map(int,input().split()))
  b=c[:k]
  b.sort()
  print(b[pos-1][1])


n = int(input())
a = [int(x) for x in input().split()]
a_sorted = sorted(a, reverse=True)

m = int(input())
for i in range(m):
    k, pos = [int(x) for x in input().split()]

    vals = a_sorted[0:k]

    result = []
    for val in a:
        if val in vals:
            result.append(val)
            vals.remove(val)

        if len(vals) == 0:
            break

    print(result[pos - 1])




n = int(input())
a = list(map(int, input().split()))
m = int(input())
for i in range(m):
    k, pos = map(int, input().split())
    save = []
    for j in range(len(a)):
        save.append(a[j])
    ans = []
    for x in range(k):
        maximum = 0
        pr = -1
        for j in range(len(save)):
            if save[j] > maximum:
                maximum = save[j]
                pr = j
        ans.append(maximum)
        save.pop(pr)
    ans.sort()
    answer = []
    for i in range(len(a)):
        if a[i] in ans:
            answer.append(a[i])
            ans.pop(ans.index(a[i]))
    print(answer[pos - 1])

n=int(input())
a=sorted(zip(list(map(int,input().split())),list(range(n))),key=lambda x:(x[0],-x[1]),reverse=True)
#print(a)
m=int(input())
for i in range(m):
    k,pos=list(map(int,input().split()))
    b=sorted(a[:k],key=lambda x:x[1])
    #print(b)
    print(b[pos-1][0])



import copy
a=[]
ai=[]
otv=''
n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(1,m+1):
    #print(ai)
    #print(a,'kkkk')
    ai=copy.deepcopy(a)
    ai.reverse()
    #print(ai)
    k,pos=list(map(int,input().split()))
    for j in range(1,n-k+1):
        #print(min(ai))
        ai.remove(min(ai))
    ai.reverse()
    otv=otv+'\n'+str(ai[pos-1])
print(otv)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
res = []
for i in range(m):
    k, pos = map(int, input().split())
    mas1 = []
    for j in range(n):
        mas1.append(a[j])
    mas2 = sorted(mas1)
    mas1.reverse()
    for j in range(n-k):
        mas1.remove(mas2[j])
    mas1.reverse()
    res.append(mas1[pos - 1])
for i in range(m):
    print(res[i])

def min_s(a, k):
    res = a.copy()
    for i in range(len(a) - k):
        m = min(res)
        res.reverse()
        res.remove(m)
        res.reverse()

    return res

n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
for _ in range(m):
    k, pos = [int(x) for x in input().split()]

    l = min_s(a, k) 

    print(l[pos-1])

def f(a):
    return -a[1]

import sys
fin = sys.stdin
n = int(input())
arr = list(map(int, fin.readline().split()))
arr_ind = list()
for i in range(n):
    arr_ind.append([arr[i], -i])
arr_ind.sort()
arr_ind.reverse()
ans_array = list()
for k in range(1, n + 1):
    ans = arr_ind[:k]
    ans.sort(key=f)
    ans_array.append(ans)

tests = int(input())
for test in range(tests):
    k, pos = map(int, input().split())
    print(ans_array[k - 1][pos - 1][0])

import copy
b=[]
a=[]
rezult=''
n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(1,m+1):
    k,pos=list(map(int,input().split()))
    b=copy.deepcopy(a)
    b.reverse()
    for j in range(1,n-k+1):
        b.remove(min(b))
    b.reverse()
    rezult=rezult+'\n'+str(b[pos-1])
print(rezult)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append([a[i], -i])
b.sort(reverse=True)
for i in range(int(input())):
    k, pos = map(int, input().split())
    ans = 0
    z = []
    for i in range(k):
        ans += b[i][0]
        z.append([-b[i][1], b[i][0]])
    z.sort()
    print(z[pos - 1][1])

n = int(input())
a = [int(i) for i in input().split()]
b = [(a[i], n - i) for i in range(n)]
b.sort(reverse=True)
b = [(b[i][0], n - b[i][1]) for i in range(n)]

m = int(input())
for qu in range(m):
    k, p = list(map(int, input().split()))
    c = b[:k]
    c.sort(key = lambda x: x[1])
    print(c[p-1][0])



n = int(input())
data = list(map(int, input().split()))
m = int(input())
for _ in range(m):
    k, pos = list(map(int, input().split()))
    s = data[:]
    ans = []
    for i in range(k):
        x = s.index(max(s))
        ans.append(x)
        s[x] = -1
    ans.sort()
    print(data[ans[pos - 1]])


n = int(input())
p = list(map(int, input().split()))
p = sorted(list(enumerate(p)), key=lambda x: -x[1])
a = [[]]
for i in range(n):
    a.append(sorted(a[-1] + [p[i]], key=lambda x: x[0]))
m = int(input())
for _ in range(m):
    x, y = list(map(int, input().split()))
    print(a[x][y - 1][1])


from math import *
from copy import copy
def maximum(list_ticket):
    for i in range(len(list_ticket)):
        if i == 0:
            ma=list_ticket[i]
        else:
            ma=max(ma,list_ticket[i])
    ma = list_ticket.index(ma)
    list_ticket.insert(ma,0)
    list_ticket.pop(ma+1)
    return ma

n = int(input())
a = list(map(int, input().split()))
m = int(input())
for i in range(m):
    b = copy(a)
    q = []
    array = list(map(int, input().split()))
    for i in range(array[0]):
        q.append(maximum(b))
    q.sort()
    q1 = []
    for i in range(len(q)):
        q1.append(a[q[i]])
    q1 = list(map(str, q1))
    print(q1[array[1]-1])

n = int(input())
A = list(map(int, input().split()))
L = A.copy()
L2 = L.copy()
A.sort()
c = int(input())
r = []
def S(x, L):
  idx = L.index(x)
  L[idx] = -1
  return [idx, x]
for i in range(c):
  k, pos = map(int, input().split())
  B = A[:0-k-1:-1]
  H = list(map(lambda x: S(x, L), B))
  H.sort()
  N = list(map(lambda x: x[1], H))
  r += [N[pos - 1]]
  L = L2.copy()
print('\n'.join(map(str, r)))

n = int(input())
arr = list(map(int, input().split()))

arr = [(i, num) for num, i in enumerate(arr)]
arr.sort(key=lambda x: (-x[0], x[1]))

m = int(input())
for q in range(m):
    k, pos = tuple(map(int, input().split()))

    now = []
    for i in arr:
        if len(now) == k:
            break
        now.append(i)

    now.sort(key=lambda x: x[1])
    # print(k, pos, now)
    print(now[pos - 1][0])