#P1470A. Strange Birthday Party

    ID: 2626 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>binary searchdpgreedysortingstwo pointers*1300

Strange Birthday Party

Description

Petya organized a strange birthday party. He invited nn friends and assigned an integer kik_i to the ii-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are mm unique presents available, the jj-th present costs cjc_j dollars (1c1c2cm1 \le c_1 \le c_2 \le \ldots \le c_m). It's not allowed to buy a single present more than once.

For the ii-th friend Petya can either buy them a present jkij \le k_i, which costs cjc_j dollars, or just give them ckic_{k_i} dollars directly.

Help Petya determine the minimum total cost of hosting his party.

The first input line contains a single integer tt (1t1031 \leq t \leq 10^3) — the number of test cases.

The first line of each test case contains two integers nn and mm (1n,m31051 \leq n, m \leq 3 \cdot 10^5) — the number of friends, and the number of unique presents available.

The following line contains nn integers k1,k2,,knk_1, k_2, \ldots, k_n (1kim1 \leq k_i \leq m), assigned by Petya to his friends.

The next line contains mm integers c1,c2,,cmc_1, c_2, \ldots, c_m (1c1c2cm1091 \le c_1 \le c_2 \le \ldots \le c_m \le 10^9) — the prices of the presents.

It is guaranteed that sum of values nn over all test cases does not exceed 31053 \cdot 10^5, and the sum of values mm over all test cases does not exceed 31053 \cdot 10^5.

For each test case output a single integer — the minimum cost of the party.

Input

The first input line contains a single integer tt (1t1031 \leq t \leq 10^3) — the number of test cases.

The first line of each test case contains two integers nn and mm (1n,m31051 \leq n, m \leq 3 \cdot 10^5) — the number of friends, and the number of unique presents available.

The following line contains nn integers k1,k2,,knk_1, k_2, \ldots, k_n (1kim1 \leq k_i \leq m), assigned by Petya to his friends.

The next line contains mm integers c1,c2,,cmc_1, c_2, \ldots, c_m (1c1c2cm1091 \le c_1 \le c_2 \le \ldots \le c_m \le 10^9) — the prices of the presents.

It is guaranteed that sum of values nn over all test cases does not exceed 31053 \cdot 10^5, and the sum of values mm over all test cases does not exceed 31053 \cdot 10^5.

Output

For each test case output a single integer — the minimum cost of the party.

Sample Input 1

2
5 4
2 3 4 3 2
3 5 12 20
5 5
5 4 3 2 1
10 40 90 160 250

Sample Output 1

30
190

Sample Input 2

1
1 1
1
1

Sample Output 2

1

Note

In the first example, there are two test cases. In the first one, Petya has 55 friends and 44 available presents. Petya can spend only 3030 dollars if he gives

  • 55 dollars to the first friend.
  • A present that costs 1212 dollars to the second friend.
  • A present that costs 55 dollars to the third friend.
  • A present that costs 33 dollars to the fourth friend.
  • 55 dollars to the fifth friend.

In the second one, Petya has 55 and 55 available presents. Petya can spend only 190190 dollars if he gives

  • A present that costs 1010 dollars to the first friend.
  • A present that costs 4040 dollars to the second friend.
  • 9090 dollars to the third friend.
  • 4040 dollars to the fourth friend.
  • 1010 dollars to the fifth friend.