Lets wish Horsbug98 on his birthday and jump right into the question.
In Chefland, $6$ new mobile brands have appeared each providing a range of smartphones. For simplicity let the brands be represented by numbers $1$ to $6$. All phones are sold at the superstore. 
There are total $N$ smartphones. Let $P_i$ & $B_i$ be the price and the brand of the $i^{th}$ smartphone. The superstore knows all the price and brand details beforehand. 
Each customer has a preference for brands. The preference is a subset of the brands available (i.e $1$ to $6$). Also, the customer will buy the $K^{th}$ costliest phone among all the phones of his preference.
You will be asked $Q$ queries. Each query consists of the preference of the customer and $K$.
Find the price the customer has to pay for his preference. If no such phone is available, print $-1$
Note that for each query the total number of smartphones is always $N$ since, after each purchase, the phones are replaced instantly.

-----Input:-----
- First Line contains $N$ and $Q$
- Second-line contains $N$ integers $P_1,P_2,...,P_N$ (Price)
- Third line contains $N$ integers $B_1,B_2,...,B_N$ (Brand)
- Each of the next Q lines contains a query, the query is describes below
- First line of each quey contains $b$ and $K$ where $b$ is the size of the preference subset.
- Second line of each query contains $b$ integers, describing the preference subset.

-----Output:-----
For each query, print the price to be paid.

-----Constraints-----
- $1 \leq N, Q, P_i \leq 10^5$
- $1 \leq B_i, b \leq 6$
- $1 \leq K \leq N$

-----Sample Input:-----
4 2
4 5 6 7 
1 2 3 4 
3 3
1 2 3
3 4
4 5 6 

-----Sample Output:-----
4

-1

-----Explaination-----
Query 1: The preference subset is {1, 2, 3}, The prices of phones available of these brands are {4, 5, 6}. The third costliest phone is 4.
Query 2: The preference subset is {4, 5, 6}, The prices of phones available of these brands are {7}.
Fouth costliest phone is required, which is not available. Hence, answer is $-1$.

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
import sys
from collections import defaultdict
from copy import copy
R = lambda t=int: t(eval(input()))
RL = lambda t=int: [t(x) for x in input().split()]
RLL = lambda n, t=int: [RL(t) for _ in range(n)]

def solve():
	(N, Q) = RL()
	P = RL()
	B = RL()
	phones = sorted(zip(P, B))
	S = defaultdict(lambda : [])
	for (p, b) in phones:
		for i in range(2 ** 7):
			if i >> b & 1:
				S[i] += [p]
	B = set(B)
	I = [0] * len(B)
	for _ in range(Q):
		(b, K) = RL()
		s = RL()
		x = 0
		for b in s:
			x += 1 << b
		if len(S[x]) < K:
			print(-1)
		else:
			print(S[x][-K])
T = 1
for t in range(1, T + 1):
	solve()


from itertools import combinations
ps = []
for i in range(1, 6 + 1):
	ps.extend(combinations(list(range(6)), i))
(n, q) = list(map(int, input().split()))
p = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [[] for _ in range(6)]
for (i, j) in zip(p, b):
	x[j - 1].append(i)
ts = {i: sorted(sum((x[j] for j in i), []), reverse=True) for i in ps}
for _ in range(q):
	(t, k) = list(map(int, input().split()))
	f = tuple([int(x) - 1 for x in input().split()])
	try:
		print(ts[f][k - 1])
	except:
		print(-1)