# #737. 【统一省选2022】卡牌

### 样例一

#### input

5
10 2 10 5 46
4
2 2 5
2 2 23
1 3
1 23



#### output

27
16
0
16



### 数据范围与提示

$1,2$ $10$ $10$ $20$ $s_i\le 30$
$3\sim 5$ $10$ $20$ $50$
$6\sim 8$ $10^6$ $1500$ $10000$ $s_i\le 30$
$9\sim 11$ $10000$ $1000$ $5000$ $s_i\le 500$
$12,13$ $1000$ $100$ $1000$
$14\sim 17$ $5000$ $600$ $7000$
$18\sim 20$ $10^6$ $1500$ $18000$