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: MEDIUM_HARD

Solutions:
n = int(input())
a = [int(i) for i in input().split()]
copy1 = a[:]
a.sort()
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	ans = [-1]
	copy = a[-k:]
	for i in copy1:
		if i in copy:
			copy.pop(copy.index(i))
			ans.append(i)
	print(ans[pos])


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])


n = int(input())
a = list(map(int, input().split()))
d = []
for i in range(n):
	d.append([a[i], -i])
d.sort(reverse=True)
e = []
for i in range(n):
	e.append([-d[i][1], d[i][0]])
m = int(input())
f = []
for i in range(m):
	(b, c) = map(int, input().split())
	f = e[:b]
	f.sort()
	print(f[c - 1][1])


n = int(input())
data = list(map(int, input().split()))
m = int(input())
for _ in range(m):
	(k, pos) = 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())
arr = list(map(int, input().split()))
q = int(input())
qs = []
for i in range(q):
	(a, b) = map(int, input().split())
	qs.append([a, b - 1, i])
qs.sort()
ret = []
used = [0 for i in range(n)]
ans = [-1 for i in range(q)]
for z in range(q):
	(l, pos, o) = qs[z]
	while len(ret) < l:
		mx = 0
		ind = -1
		for i in range(n):
			if not used[i]:
				if mx < arr[i]:
					mx = arr[i]
					ind = i
		used[ind] = 1
		ret.append(mx)
	c = []
	for i in range(n):
		if used[i]:
			c.append(arr[i])
	ans[qs[z][2]] = c[pos]
for i in range(q):
	print(ans[i])


n = int(input())
a = list(map(int, input().split()))
s_a = sorted(a)
m = int(input())
req = []
for _ in range(m):
	req.append(list(map(int, input().split())))
d = dict()
for r in req:
	if r[0] in d.keys():
		print(d[r[0]][r[1] - 1])
	else:
		del_indx = []
		for e in s_a[:n - r[0]]:
			for i in reversed(range(n)):
				if a[i] == e:
					if i not in del_indx:
						del_indx.append(i)
						break
		new_a = []
		for i in range(n):
			if i not in del_indx:
				new_a.append(a[i])
		d[r[0]] = new_a
		print(d[r[0]][r[1] - 1])


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

class FenwickTree:

	def __init__(self, x):
		self.bit = x
		for i in range(len(x)):
			j = i | i + 1
			if j < len(x):
				x[j] += x[i]

	def update(self, idx, x):
		while idx < len(self.bit):
			self.bit[idx] += x
			idx |= idx + 1

	def query(self, end):
		x = 0
		while end:
			x += self.bit[end - 1]
			end &= end - 1
		return x

	def findkth(self, k):
		idx = -1
		for d in reversed(range(len(self.bit).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(self.bit) and k >= self.bit[right_idx]:
				idx = right_idx
				k -= self.bit[idx]
		return idx + 1

	def printpref(self):
		out = []
		for i in range(1, len(self.bit) + 1):
			out.append(self.query(i))
		print(out)

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def solve(case):
	n = int(inp())
	a = lis()
	queries = []
	m = int(inp())
	for i in range(m):
		(k, pos) = sep()
		queries.append((k, pos, i))
	queries.sort()
	b = sorted(a)[::-1]
	ind = {}
	for i in range(n):
		if a[i] not in ind:
			ind[a[i]] = deque([i])
		else:
			ind[a[i]].append(i)
	sl = SortedList()
	currind = 0
	ans = [-1] * m
	for (k, pos, where) in queries:
		while currind < k:
			sl.add(ind[b[currind]].popleft())
			currind += 1
		ans[where] = a[sl[pos - 1]]
	for i in ans:
		print(i)
testcase(1)


import math

def getFirstSetBitPos(n):
	return math.log2(n & -n) + 1

def find_div(x):
	ls = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			ls.append(i)
			if i != x // i:
				ls.append(x // i)
	return sorted(ls)
from collections import Counter
n = int(input())
ar = [(int(x), i) for (i, x) in enumerate(input().split())]
arr = sorted(ar, key=lambda x: (x[0], -1 * x[1]))
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	ls = sorted(arr[-k:], key=lambda x: x[1])
	print(ls[pos - 1][0])


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
d = {}
for i in sorted(enumerate(R()), reverse=True, key=lambda x: x[1]):
	if i[1] not in d:
		d[i[1]] = []
	d[i[1]] += (i,)
	d[i[1]].sort(key=lambda x: x[0])
a = []
for i in d:
	a.extend(d[i])
m = []
x = []
for i in range(n):
	x += (a[i],)
	x.sort(key=lambda x: x[0])
	m.append(x.copy())
for i in range(I()):
	(k, pos) = R()
	print(m[k - 1][pos - 1][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])


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)


def main():
	import os
	from io import BytesIO
	input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
	n = int(input())
	a = [(int(el), -ind) for (ind, el) in enumerate(input().split())]
	a.sort(reverse=True)
	for i in range(int(input())):
		(x, y) = map(int, input().split())
		t = sorted(a[:x], key=lambda x: -x[1])
		print(t[y - 1][0])
main()


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)))


a = int(input())
b = list(map(int, input().split()))
for i in range(a):
	b[i] = (b[i], -i)
b.sort()
k = int(input())
for q in range(k):
	a = list(map(int, input().split()))
	l = a[0]
	p = a[1]
	print(sorted(b[-l:], key=lambda x: -x[1])[p - 1][0])


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])


import sys

def main():
	n = int(input())
	al = [[int(x), n - i] for (i, x) in enumerate(input().split())]
	al.sort()
	al.reverse()
	arr = [[[] for i in range(n)] for i in range(n)]
	for i in range(1, n + 1):
		for j in range(i - 1, n):
			arr[j][n - al[i - 1][1]] = al[i - 1][0]
	for i in range(n):
		arr[i] = list(filter(None, arr[i]))
	q = int(input())
	for _ in range(q):
		(k, ind) = map(int, input().split())
		print(arr[k - 1][ind - 1])
main()


import sys as _sys

def main():
	t = 1
	for i_t in range(t):
		(n,) = _read_ints()
		a = tuple(_read_ints())
		(m,) = _read_ints()
		queries = (tuple(_read_ints()) for i_query in range(m))
		result = process_queries(a, queries)
		print(*result, sep='\n')

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split())

def process_queries(sequence, queries):
	sequence = tuple(sequence)
	sorted_sequence = sorted(sequence, reverse=True)
	for (k, pos) in queries:
		pos -= 1
		k_max_elems = sorted_sequence[:k][::-1]
		seq = sequence
		subseq = []
		while len(subseq) < k:
			for i_next_elem in range(len(k_max_elems)):
				next_elem = k_max_elems[i_next_elem]
				seq_after = seq[seq.index(next_elem) + 1:]
				elems_remain = k_max_elems[:i_next_elem] + k_max_elems[i_next_elem + 1:]
				if _contains_elems(seq_after, elems_remain):
					seq = seq_after
					k_max_elems = elems_remain
					subseq.append(next_elem)
					break
		yield subseq[pos]

def _contains_elems(seq, elems):
	seq = sorted(seq)
	subseq = sorted(elems)
	i_seq = 0
	i_subseq = 0
	while i_seq < len(seq) and i_subseq < len(subseq):
		if seq[i_seq] == subseq[i_subseq]:
			i_subseq += 1
		i_seq += 1
	return i_subseq == len(subseq)
main()


n = int(input())
a = [int(x) for x in input().split()]
z = a[:]
z.sort(reverse=True)
an = [[] for i in range(n + 1)]
an[0] = a[:]
for i in range(n):
	for j in range(len(a) - 1, -1, -1):
		if a[j] == z[-1]:
			del a[j]
			z.pop()
			break
	an[i + 1] = a[:]
an = an[::-1]
for j in range(int(input())):
	(x, y) = map(int, input().split())
	print(an[x][y - 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])


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a, reverse=True)
for _ in range(int(input())):
	(k, pos) = map(int, input().split())
	d = defaultdict(int)
	for i in range(k):
		d[b[i]] += 1
	count = 0
	num = -1
	for x in a:
		if d[x]:
			d[x] -= 1
			count += 1
		if count == pos:
			num = x
			break
	print(num)


from math import *
import os, sys
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append((-a[i], i))
b.sort()
for i in range(int(input())):
	(k, pos) = map(int, input().split())
	tmp = []
	for j in range(k):
		tmp.append(b[j][1])
	tmp.sort()
	print(a[tmp[pos - 1]])


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())
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]])


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


n = int(input())
arr = list(map(int, input().split()))
m = int(input())
q = []
for i in range(m):
	(a, b) = map(int, input().split())
	q.append((a, b))

def f(arr, m):
	vis = [False] * len(arr)
	arr2 = []
	for i in range(len(arr)):
		arr2.append([arr[i], n - i])
	arr2.sort(reverse=True)
	arr2 = arr2[:m]
	for i in range(len(arr2)):
		arr2[i][1] = n - arr2[i][1]
	arr2.sort(key=lambda x: x[1])
	res = []
	for i in range(len(arr2)):
		res.append(arr2[i][0])
	return res
for i in q:
	x = f(arr, i[0])
	print(x[i[1] - 1])


n = int(input())
s = sorted([[v, -i] for (i, v) in enumerate(map(int, input().split()))])
for _ in range(int(input())):
	(k, i) = map(int, input().split())
	ans = sorted(s[-k:], key=lambda x: -x[1])
	print(ans[i - 1][0])


n = int(input())
b = list(map(int, input().split()))
a = []
for i in range(n):
	a.append([b[i], n - i])
a.sort()
a.reverse()
p = []
t = []
for i in range(n):
	t.append(a[i])
	d = t.copy()
	d.sort(key=lambda x: -x[1])
	p.append(d)
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	d = p[k - 1].copy()
	print(d[pos - 1][0])


n = int(input())
arr = list(map(int, input().split()))
arr_sorted = [(arr[i], i) for i in range(n)]
arr_sorted.sort(key=lambda el: (el[0], -el[1]), reverse=True)
m = int(input())
for req_i in range(m):
	(k, pos) = map(int, input().split())
	pos -= 1
	cur_arr = arr_sorted[:k]
	cur_arr.sort(key=lambda el: el[1])
	print(cur_arr[pos][0])


import sys
import bisect
import heapq
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(ri())
ar = Ri()
arr = [(ar[i], i) for i in range(n)]
arr.sort(key=lambda x: -x[0])
for _ in range(int(ri())):
	(a, b) = Ri()
	temp = []
	for i in range(a):
		temp.append(arr[i][1])
	temp.sort()
	print(ar[temp[b - 1]])


n = int(input())
s = list(map(int, input().split()))
for i in range(n):
	s[i] = (s[i], i)
mx = sorted(s, key=lambda y: y[0], reverse=True)
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	pos -= 1
	a = 0
	last = mx[0][0]
	res = []
	d = dict()
	d2 = dict()
	for x in range(k):
		if mx[x][0] not in d:
			d[mx[x][0]] = 1
		else:
			d[mx[x][0]] += 1
	for x in range(n):
		if mx[x][0] != last:
			a += 1
			last = mx[x][0]
		if a == k:
			break
		if mx[x][0] not in d2:
			d2[mx[x][0]] = [mx[x][1]]
		else:
			d2[mx[x][0]].append(mx[x][1])
	for a in list(d.keys()):
		d2[a].sort()
		for j in range(d[a]):
			res.append((a, d2[a][j]))
	res = sorted(res, key=lambda y: y[1])
	print(res[pos][0])


def mergesort(l, r, arr, pos):
	if r - l == 1:
		return (arr, pos)
	m = (l + r) // 2
	(arr, pos) = mergesort(l, m, arr, pos)
	(arr, pos) = mergesort(m, r, arr, pos)
	c = [0 for i in range(r)]
	d = [0 for i in range(r)]
	poi_a = l
	poi_b = m
	for i in range(l, r):
		if poi_a == m:
			c[i] = arr[poi_b]
			d[i] = pos[poi_b]
			poi_b += 1
		elif poi_b == r:
			c[i] = arr[poi_a]
			d[i] = pos[poi_a]
			poi_a += 1
		elif a[poi_a] > arr[poi_b]:
			c[i] = arr[poi_a]
			d[i] = pos[poi_a]
			poi_a += 1
		else:
			c[i] = arr[poi_b]
			d[i] = pos[poi_b]
			poi_b += 1
	for i in range(l, r):
		arr[i] = c[i]
		pos[i] = d[i]
	return (arr, pos)
n = int(input())
a = list(map(int, input().split()))
p = [i for i in range(n)]
temp = a[:]
(a, p) = mergesort(0, n, a, p)
for m in range(int(input())):
	(k, pos) = map(int, input().split())
	j = k
	while j < n and a[j - 1] == a[j]:
		j += 1
	i = k - 1
	l = 1
	while i > 0 and a[i - 1] == a[i]:
		i -= 1
		l += 1
	m = sorted(p[i:j])
	res = sorted(m[:l] + p[:i])
	print(temp[res[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)
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[pos - 1][0])


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) = 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])


from sys import stdin
n = int(stdin.readline())
alist = list(map(int, stdin.readline().split()))
aindlist = sorted([(elem, i) for (i, elem) in enumerate(alist)], key=lambda x: (-x[0], x[1]))
m = int(stdin.readline())
ans = []
for _ in range(m):
	(k, pos) = map(int, stdin.readline().split())
	temp = [x[1] for x in aindlist[:k]]
	temp.sort()
	ans.append(alist[temp[pos - 1]])
print(*ans, sep='\n')


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())
l = [int(j) for j in input().split()]
m = int(input())
d = dict()
for i in range(n):
	if l[i] in d:
		d[l[i]].append(i)
	else:
		d[l[i]] = [i]
d = sorted(d.items(), reverse=True)
for que in range(m):
	(k, pos) = [int(j) for j in input().split()]
	min_ = []
	i = 0
	j = 0
	while k > 0:
		k -= 1
		min_.append(d[i][1][j])
		j += 1
		if j == len(d[i][1]):
			i += 1
			j = 0
	min_.sort()
	print(l[min_[pos - 1]])


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)


def main():
	n = int(input())
	a = list(enumerate(map(int, input().split())))
	a.sort(key=lambda item: (item[1], -item[0]))
	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())
b = list(map(int, input().split()))
a = [[0] * 2 for i in range(n)]
for i in range(n):
	a[i][0] = b[i]
	a[i][1] = i
for i in range(n - 1):
	for j in range(n - i - 1):
		if a[j][0] > a[j + 1][0]:
			(a[j], a[j + 1]) = (a[j + 1], a[j])
		elif a[j][0] == a[j + 1][0] and a[j][1] < a[j + 1][1]:
			(a[j], a[j + 1]) = (a[j + 1], a[j])
m = int(input())
for k in range(m):
	(k, ind) = map(int, input().split())
	ans = [[0] * 2 for i in range(k)]
	for i in range(k):
		ans[i][0] = a[n - i - 1][1]
		ans[i][1] = a[n - i - 1][0]
	ans.sort()
	print(ans[ind - 1][1])


n = int(input())
a = list(map(int, input().split()))
a1 = sorted(a, key=lambda x: -x)
q = int(input())
for i in range(q):
	(k, pos) = map(int, input().split())
	pos -= 1
	notused = {}
	for j in a1[:k]:
		if j in notused:
			notused[j] += 1
		else:
			notused[j] = 1
	for j in a:
		if j in notused:
			if pos > 0:
				if notused[j] > 1:
					notused[j] -= 1
				else:
					notused.pop(j)
				pos -= 1
			else:
				print(j)
				break


import sys
from collections import defaultdict
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
l = [i for i in arr]
for i in range(n):
	arr[i] = [arr[i], -i]
arr.sort()
dic = defaultdict(list)
z = len(arr)
m = int(sys.stdin.readline())
for _ in range(m):
	(n, pos) = map(int, sys.stdin.readline().split())
	if dic[n] != []:
		print(l[dic[n][pos - 1]])
	else:
		dic[n] = [0 for _ in range(n)]
		ind = n - 1
		for i in range(z - 1, z - n - 1, -1):
			dic[n][ind] = -arr[i][1]
			ind -= 1
		dic[n].sort()
		print(l[dic[n][pos - 1]])


def test(a, k, pos):
	r = list(reversed(sorted(a.copy())))
	countLast = r[k - 1]
	s = 0
	for i in range(k, len(r)):
		if r[i] == countLast:
			s += 1
	ans = []
	a = list(reversed(a))
	for i in range(len(a)):
		if a[i] > countLast or (a[i] == countLast and s == 0):
			ans.append(a[i])
		elif a[i] == countLast:
			s -= 1
	print(list(reversed(ans))[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())
	test(a, k, pos)


n = int(input())
sequence = list(map(int, input().split()))
array = list(sequence)
array.sort(reverse=True)
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	D = dict()
	for elem in array[:k]:
		if elem in D:
			D[elem] += 1
		else:
			D[elem] = 1
	for elem in sequence:
		if elem in D and D[elem] != 0:
			D[elem] -= 1
			if pos == 1:
				print(elem)
				break
			else:
				pos -= 1


n = int(input())
a = [int(x) for x in input().split()]
b = [[] for i in range(n + 3)]
for g in range(1, n + 1):
	k = g
	cnt = 0
	mm = 10 ** 10
	m = 0
	for i in range(n):
		if len(b[g]) != 0:
			mm = min(b[g])
		if cnt == k:
			if a[i] > mm:
				for j in range(k - 1, -1, -1):
					if b[g][j] == mm:
						b[g].pop(j)
						break
				b[g].append(a[i])
		else:
			b[g].append(a[i])
			cnt += 1
		m = max(b[g])
m = int(input())
for i in range(m):
	(k, pos) = [int(x) for x in input().split()]
	pos -= 1
	print(b[k][pos])


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])


from collections import Counter

def main():
	n = int(input())
	a = readIntArr()
	b = sorted(a, reverse=True)
	m = int(input())
	allans = []
	for _ in range(m):
		(k, pos) = readIntArr()
		cnt = Counter(b[:k])
		totalCnts = 0
		for x in a:
			if cnt[x] > 0:
				cnt[x] -= 1
				totalCnts += 1
				if totalCnts == pos:
					allans.append(x)
					break
	multiLineArrayPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


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])


def get_index(lt, vec):
	max_el = 0
	pos = None
	for i in range(len(vec)):
		if i not in lt:
			if max_el < vec[i]:
				max_el = vec[i]
				pos = i
	return pos
n = int(input())
vec = [int(x) for x in input().split()]
lst = [[vec.index(max(vec))]]
for i in range(n - 1):
	lt = list(lst[i])
	ind = get_index(lt, vec)
	lt.append(ind)
	lst.append(lt)
for l in lst:
	l.sort()
m = int(input())
for i in range(m):
	(k, pos) = [int(x) for x in input().split()]
	print(vec[lst[k - 1][pos - 1]])


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a[i] = (a[i], -i)
a.sort()
m = int(input())
for j in range(m):
	t = list(map(int, input().split()))
	k = t[0]
	p = t[1]
	print(sorted(a[-k:], key=lambda x: -x[1])[p - 1][0])


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())
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])


import os
import sys
from io import BytesIO, IOBase

class SortedList:

	def __init__(self, iterable=None, _load=200):
		if iterable is None:
			iterable = []
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def main():
	n = int(input())
	aa = list(map(int, input().split()))
	a = [(v, n - i - 1) for (i, v) in enumerate(aa)]
	a.sort()
	a.reverse()
	q = []
	for i in range(int(input())):
		(x, y) = map(int, input().split())
		q.append((x, y, i))
	q.sort(key=lambda x: x[0])
	b = SortedList()
	ans = [0] * len(q)
	j = 0
	for i in q:
		while j < i[0]:
			b.add(-(a[j][1] - n + 1))
			j += 1
		ans[i[2]] = aa[b[i[1] - 1]]
	for i in ans:
		print(i)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = [int(i) for i in input().split()]
b = sorted(a)
b.reverse()
m = int(input())
for _ in range(m):
	(k, pos) = map(int, input().split())
	x = 0
	j = 0
	d = dict()
	ans = 0
	for i in b[:k]:
		d[i] = d.get(i, 0) + 1
	while x != pos:
		u = a[j]
		if u in d:
			d[u] -= 1
			x += 1
			if d[u] == 0:
				del d[u]
		j += 1
		ans = u
	print(ans)


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(now[pos - 1][0])


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a1 = list(map(int, input().split()))
a = list()
for i in range(n):
	a.append((a1[i], n - i))
a.sort(reverse=True)
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	c = list()
	for j in range(k):
		c.append(n - a[j][1])
	c.sort()
	res = a1[c[pos - 1]]
	print(res)


m = int(input())
line = [int(i) for i in input().split()]
for i in range(int(input())):
	false_line = list(line)
	(k, pos) = map(int, input().split())
	while len(false_line) > k:
		x = min(false_line)
		rang = iter(range(-1, -len(false_line) - 1, -1))
		j = next(rang)
		while j > -len(false_line) - 1:
			if false_line[j] == x:
				del false_line[j]
				if len(false_line) == k:
					break
			else:
				try:
					j = next(rang)
				except StopIteration:
					break
	print(false_line[pos - 1])


import itertools
import functools
from operator import itemgetter

def cmp(a, b):
	if a[0] > b[0]:
		return -1
	elif a[0] < b[0]:
		return 1
	elif a[1] < b[1]:
		return -1
	elif a[1] > b[1]:
		return 1
	else:
		return 0
n = int(input())
a = list(map(int, input().split()))
c = a[:]
c = list(zip(a, itertools.count(0)))
c = sorted(c, key=functools.cmp_to_key(cmp))
h = c[:]
m = int(input())
for i in range(m):
	(k, pos) = map(int, input().split())
	h = sorted(c[:k], key=itemgetter(1))
	print(h[pos - 1][0])


n = int(input())
line = list(map(int, input().split()))
m = int(input())
for _ in range(m):
	(k, pos) = map(int, input().split())
	lf = line[:]
	while len(lf) > k:
		j = -1
		x = min(lf)
		while j > -len(lf) - 1:
			if lf[j] == x:
				del lf[j]
				if len(lf) == k:
					break
			else:
				j -= 1
	print(lf[pos - 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])


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])


n = int(input())
aa = [int(i) for i in input().split()]
dic = {}
for i in range(0, n):
	if aa[i] not in dic:
		dic[aa[i]] = [i]
	else:
		dic[aa[i]].append(i)
ll = sorted(dic)[::-1]
m = int(input())
for _ in range(0, m):
	(k, pos) = map(int, input().split())
	ans = []
	for i in range(0, len(ll)):
		if len(dic[ll[i]]) < k:
			ans += dic[ll[i]]
			k -= len(dic[ll[i]])
		else:
			ans += dic[ll[i]][:k]
			break
	print(aa[sorted(ans)[pos - 1]])


n = int(input())
a = list(map(int, input().split()))
a1 = sorted(a, key=lambda x: -x)
m = int(input())
for i in range(m):
	(k, p) = list(map(int, input().split()))
	c = {}
	c1 = {}
	s = []
	for j in range(n + 1):
		s.append({})
	pos = {}
	for j in range(n):
		c[a1[j]] = 0
		c1[a1[j]] = 0
		s[0][a[j]] = 0
		pos[a1[j]] = []
	for j in range(n):
		s[0][a[j]] += 1
	for j in range(n):
		for t in range(n):
			s[j + 1][a[t]] = s[j][a[t]]
		s[j + 1][a[j]] -= 1
	b = []
	for j in range(k):
		c[a1[j]] += 1
	for j in range(k, n):
		c1[a1[j]] += 1
	ns = []
	us = [0] * n
	ans = []
	for j in range(n - 1, -1, -1):
		if c1[a[j]] ^ 0:
			c1[a[j]] -= 1
		else:
			ans.append(a[j])
	for j in range(len(ans) // 2):
		(ans[j], ans[len(ans) - 1 - j]) = (ans[len(ans) - 1 - j], ans[j])
	print(ans[p - 1])


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
for i in range(m):
	(kj, posj) = map(int, input().split())
	a_copy = [x for x in a]
	for u in range(n - kj):
		mid = 0
		for uuu in range(len(a_copy)):
			if a_copy[uuu] <= a_copy[mid]:
				mid = uuu
		a_copy.pop(mid)
	print(a_copy[posj - 1])