#P12777. 理解 加强版

理解 加强版

Description

Saki is practicing modern literature reading conprehension using the method recommended by Yuta.

There are nn historical events, numbered from 11 to nn, where each event may have a prerequisite event with a smaller number, or it may have none. Formally, for event ii, let pip_i denote the number of its prerequisite event, satisfying pi<ip_i < i. If pi=0p_i = 0, it means the event has no prerequisite.

Saki has two ways to recall a historical event: recollection and association. If she recollects, she can spend rur_u time to recall event uu. If she associates, she can choose any event uu that she has already recalled and spend tvt_v time to recall an event vv where pv=up_v = u.

However, her brain capacity is limited, so she can only recall up to kk events simultaneously. She can choose to forget any event she has already recalled at any moment, and forgetting an event does not take any time. She can recall the events she has previously forgotten.

Now, she has mm reading questions, and the ii-th question requires her to recall event xix_i. She can solve the ii-th problem immediately upon recalling event xix_i, and the time taken is negligible. She wants to know the minimum amount of time she needs to spend to solve all the questions.

Input Format

The first line contains an integer TT, denoting the number of test cases.

For each test case, the first line contains three integers, n,mn,m and kk, representing the number of historical events, the number of reading questions, respectively and the number of events that she can recall at the same time.

The second line is consisted of nn integers representing p1,,pnp_1,\dots,p_n.

The third line is consisted of nn integers representing r1,,rnr_1,\dots,r_n.

The fourth line is consisted of nn integers representing t1,,tnt_1,\dots,t_n. It is guaranteed that when pi=0p_i=0, ti=0t_i=0.

The fifth line is consisted of mm integers representing x1,,xmx_1,\dots,x_m.

Output Format

For each test case, output a single integer on a line indicating the minimum amount of time she needs to spend to solve all the questions.

2
5 3 3
0 1 1 0 3
1 2 3 4 5
0 1 1 0 2
2 4 5
5 3 2
0 1 1 2 3
1 2 3 4 5
0 1 1 2 2
2 4 5

9
8

1
13 13 3
0 1 2 3 3 4 4 5 5 6 7 8 9
1 3 5 7 7 10 10 10 10 13 13 13 13
0 1 1 1 1 2 2 2 2 2 2 2 2
1 2 3 4 5 6 7 8 9 10 11 12 13

22

Hint

For all of the testdata, 1T301\le T\le30, 1n,m50001\le n,m\le5000, 1k51\le k\le5, 0pi<i0\le p_i<i, 0ri,ti1090\le r_i,t_i\le10^9, 1xin1\le x_i\le n.