You are given an array A of size N. Let us list down all the subarrays of the given array. There will be a total of N * (N + 1) / 2 subarrays of the given array. Let us sort each of the subarrays in descending order of the numbers in it. 

Now you want to sort these subarrays in descending order. You can compare two subarrays B, C, as follows.

compare(B, C):
Append N - |B| zeros at the end of the array B.
Append N - |C| zeros at the end of the array C.
for i = 1 to N:
if B[i] < C[i]:
return B is less than C
if B[i] > C[i]:
return B is greater than C
return B and C are equal.

You are given M queries asking for the maximum element in the pth subarray (1-based indexing).

-----Input-----
The first line of input contains T, the number of test cases.
The first line of each test case contains two space separated integers N and M, denoting the array size and the number of queries respectively.
The next line contains N space-separated integers denoting the array elements.

Each of the next M lines contains a single integer - p.

-----Output-----
Output a single integer corresponding to the maximum element in the pth subarray.

-----Constraints-----
- 1 ≤ Ai ≤ 109
- 1 ≤ p ≤ N+1C2

-----Subtasks-----Subtask #1 (20 points):
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 200
- 1 ≤ M ≤ 104
Subtask #2 (30 points):
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 3000
- 1 ≤ M ≤ 104
Subtask #3 (50 points):
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 105
- 1 ≤ M ≤ 105

-----Example-----
Input:1
4 2
3 1 2 4
1
5

Output:4
3

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'for _ in range(int(input())):\n N, M = map(int, input().split())\n arr = list(map(int, input().split()))\n arr1 = sorted(arr, reverse=True)\n lst = []\n for i in range(N):\n  for j in range(i, N):\n   x = arr[i:j+1]\n   x.sort(reverse=True)\n   x.extend([0]*(N-len(x)))\n   lst.append(x)\n lst.sort(reverse=True)\n  \n for j in range(M):\n  p = int(input())-1\n  print(lst[p][0])'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13433